LlamaIndex RAG 管道與 API Store Hub 集成

在同一 https://apistorehub.com /v1 网关上同步配置答案生成 LLM 和嵌入模型,以实现准确的内部文档索引。

準備好透過單一 API key、VND 支付和 API Store Hub 上的多供應商故障轉移將 AI 投入生產了嗎?

LlamaIndex RAG 管道與 API Store Hub 集成 visual architecture diagram — API Store Hub
LlamaIndex RAG 管道與 API Store Hub 集成 · Base URL https://apistorehub.com · Key prefix sk-ash-

套件安裝命令

LanguagePython
RuntimePython 3.10+, llama-index-core, llama-index-llms-openai-like
ProtocolOpenAI Compatible (/v1/chat/completions, /v1/embeddings)
套件安裝命令pip install -U llama-index-core llama-index-llms-openai-like

只需 3 步驟即可快速安裝

  1. 在API Store Hub上創建API key: 登录 API Store Hub 仪表板,创建带有 sk-ash- 前缀的密钥,如有必要,设置每日/每月支出限额。
  2. 安裝 SDK 並配置基本 URL: 安裝正版庫包,然後將環境變數設定為指向https://apistorehub.com,以向/v1/chat/completions端點發送請求。
  3. 呼叫模型並啟用流/重試: 尝试使用显式超时调用 gemini-4-neon,然后使用抖动重试;每个呼叫都有token日志、TTFT和透明费用。

準備運行生產的範例原始程式碼

Python

import os
from llama_index.core import Document, Settings, VectorStoreIndex
from llama_index.llms.openai_like import OpenAILike

Settings.llm = OpenAILike(
    model="gemini-4-neon",
    api_base="https://apistorehub.com/v1",
    api_key=os.environ["API_KEY"],
    context_window=200000,
    is_chat_model=True,
    is_function_calling_model=True,
)

docs = [Document(text="Credit ST uses a 1:1 VND rate across all gateway models.")]
index = VectorStoreIndex.from_documents(docs)
engine = index.as_query_engine(similarity_top_k=5)
print(engine.query("How does ST billing work?"))

cURL

curl https://apistorehub.com/v1/chat/completions \
  -H "Authorization: Bearer sk-ash-your_key" \
  -H "Content-Type: application/json" \
  -d '{"model":"gemini-4-neon","messages":[{"role":"system","content":"Answer only from context."},{"role":"user","content":"Context: 1 ST = 1 VND. Question: What is 1 ST?"}]}'

建議型號及實際價格表

Model价格Token情境和端點
Gemini 4 Neon20,400 ST / 1M tokens2M
Claude Sonnet 5.57,700 ST / 1M tokens1M
DeepSeek V4 Flash1,500 ST / 1M tokens1M

實際運行時的最佳化原則

  • 建議使用 chunk_size=512–1024 token 並僅選擇 top-k 最相關的區塊,以保持上下文緊湊並節省 token 成本。
  • 對於長響應 (> 500 token) 始終啟用stream=true,以保持連接順暢並減少第一個 token 逾時 (TTFT)。
  • 不要在客戶端原始程式碼中硬編碼API key;從環境變數讀取並定期循環 API Store Hub 控制台上的金鑰。
  • 為代碼429/502/529安裝帶有抖動的指數退避重試機制,並在同一1 API key上準備備份模型。

常見問題

將 LlamaIndex RAG Pipeline 與 API Store Hub 整合是否需要修復舊的函數呼叫邏輯?
不需要。 API Store Hub 保留了標準格式 OpenAI (https://apistorehub.com /v1) 和 Anthropic 訊息 (https://apistorehub.com /v1/messages),因此您只需更改 Base URL 和 API key sk-ash- 即可。
1 API key 可以用於串流、函數呼叫和嵌入嗎?
有。 API Store Hub 上的單一金鑰涵蓋了整個 187 模型,包括 SSE 流、JSON Schema strict、工具呼叫和向量嵌入。
票價和速度限制是如何控制的?
所有通話均根據 token 或 API Store Hub 儀表板上的請求透明計費,不扣除負錢包,並允許為每個 API key 設定單獨的支出上限。