API Store Hub 上的函數呼叫與結構化 JSON 架構

強制模型根據 Zod/JSON Schema(嚴格:true)傳回 100% 有效的 JSON,將資料直接倒入資料庫和業務 API。

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

API Store Hub 上的函數呼叫與結構化 JSON 架構 visual architecture diagram — API Store Hub
API Store Hub 上的函數呼叫與結構化 JSON 架構 · Base URL https://apistorehub.com · Key prefix sk-ash-

套件安裝命令

LanguageTypeScript
RuntimeNode.js 20+ / Python 3.10+, OpenAI & Anthropic SDK
ProtocolOpenAI Compatible (/v1/chat/completions) & Anthropic (/v1/messages)
套件安裝命令npm install openai zod

只需 3 步驟即可快速安裝

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

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

TypeScript

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://apistorehub.com/v1", apiKey: process.env.API_KEY });

const res = await client.chat.completions.create({
  model: "gpt-6.2-sol",
  messages: [{ role: "user", content: "Extract order: 2 keyboards at 450000 VND for Minh." }],
  response_format: {
    type: "json_schema",
    json_schema: {
      name: "order_extract",
      strict: true,
      schema: {
        type: "object",
        properties: {
          customer: { type: "string" },
          item: { type: "string" },
          qty: { type: "integer" },
          unit_price_vnd: { type: "integer" }
        },
        required: ["customer", "item", "qty", "unit_price_vnd"],
        additionalProperties: false
      }
    }
  }
});
console.log(JSON.parse(res.choices[0].message.content || "{}"));

cURL

curl https://apistorehub.com/v1/chat/completions \
  -H "Authorization: Bearer sk-ash-your_key" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-6.2-sol","response_format":{"type":"json_object"},"messages":[{"role":"system","content":"Return JSON only."},{"role":"user","content":"Extract city from: Giao hang tai Da Nang"}]}'

建議型號及實際價格表

Model价格Token情境和端點
GPT 6.2 Sol6,700 ST / 1M tokens1.1M
Claude Sonnet 5.57,700 ST / 1M tokens1M
Gemini 4 Neon20,400 ST / 1M tokens2M

實際運行時的最佳化原則

  • 始终声明 extraProperties: false 并在启用 strict: true 时列出每个嵌套对象所需的完整数组。
  • 對於長響應 (> 500 token) 始終啟用stream=true,以保持連接順暢並減少第一個 token 逾時 (TTFT)。
  • 不要在客戶端原始程式碼中硬編碼API key;從環境變數讀取並定期循環 API Store Hub 控制台上的金鑰。
  • 為代碼429/502/529安裝帶有抖動的指數退避重試機制,並在同一1 API key上準備備份模型。

常見問題

將 Function Calling & Structured JSON 與 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 設定單獨的支出上限。