API Store Hub での LlamaIndex RAG パイプライン連携
単一の https://apistorehub.com/v1 ゲートウェイで生成 LLM と Embedding モデルを統一設定し、高精度な社内文書 RAG を構築します。
API Store Hub の単一 API キー・透明な料金・マルチプロバイダー切替で本番運用を始めましょう。
インストールコマンド
| Language | Python |
|---|---|
| Runtime | Python 3.10+, llama-index-core, llama-index-llms-openai-like |
| Protocol | OpenAI Compatible (/v1/chat/completions, /v1/embeddings) |
| インストールコマンド | pip install -U llama-index-core llama-index-llms-openai-like |
3 ステップのクイック導入
- API Store Hub で API キーを発行: API Store Hub の管理画面で sk-ash- プレフィックスのキーを発行し、必要に応じて利用上限を設定します。
- SDK をインストールし Base URL を設定: 公式パッケージをインストールし、/v1/chat/completions 向けの環境変数で https://apistorehub.com を指定します。
- ストリーミングとリトライ付きで実行: 明示的なタイムアウトとジッター付きリトライで gemini-4-neon を呼び出します。トークン数・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?"}]}'推奨モデルと最新料金
| モデル | トークン単価 | コンテキストとエンドポイント |
|---|---|---|
| Gemini 4 Neon | 20,400 ST / 1M tokens | 2M |
| Claude Sonnet 5.5 | 7,700 ST / 1M tokens | 1M |
| DeepSeek V4 Flash | 1,500 ST / 1M tokens | 1M |
本番運用のチェックリスト
- chunk_size を 512〜1024 トークンに保ち top-k のみ抽出することで、精度を保ちつつトークン消費を抑えられます。
- 長文出力(500 トークン超)では stream=true を有効化し、TTFT 短縮とタイムアウト防止を徹底してください。
- クライアントコードに API キーを埋め込まず、サーバー側の環境変数から読み込み API Store Hub で定期ローテーションしてください。
- 429/502/529 にはジッター付き指数バックオフを実装し、同一 API キーでフォールバックモデルを用意してください。
よくある質問
- LlamaIndex RAG Pipeline を API Store Hub に接続する際、既存コードの書き換えは必要ですか?
- いいえ。API Store Hub は OpenAI(https://apistorehub.com/v1)および Anthropic Messages(https://apistorehub.com/v1/messages)仕様に準拠しているため、Base URL と sk-ash- キーの変更だけで動作します。
- 1 つの API キーでストリーミング・Function Calling・Embeddings を併用できますか?
- はい。API Store Hub の 1 つのキーで全 187 モデル(SSE ストリーミング・厳格 JSON Schema・ツール呼び出し・Embeddings)を利用できます。
- 料金とレート制限はどのように管理されますか?
- すべてのリクエストは API Store Hub コンソールでトークンまたはリクエスト単位で透明に課金され、残高がマイナスにならずキー別の上限も設定可能です。