跳至主要內容
所有用戶端
OpenAI, Anthropic & Vercel AI SDKs1M Context · ZDR

curl 與官方 SDK

驗證金鑰可用的最短指令,以及兩種官方 SDK 串接寫法。

基礎網址
https://api.bf16.ai/v1
協定
openai-completions

適用對象
在自有程式碼中直接串接 bf16 的所有開發者。

架構原理與接入優勢

Unified multi-protocol gateway on https://api.bf16.ai supporting OpenAI Chat Completions, OpenAI Responses, Anthropic Messages, and Vercel AI SDK
One sk-bf16-v1-* key speaks all three wire protocols against api.bf16.ai: /v1/chat/completions, /v1/responses, and /v1/messages.

bf16.ai exposes three native wire surfaces on a single prepaid USD balance: OpenAI Chat Completions (`POST https://api.bf16.ai/v1/chat/completions`), stateless OpenAI Responses (`POST https://api.bf16.ai/v1/responses`), and Anthropic Messages (`POST https://api.bf16.ai/v1/messages`).

Every response includes `x-request-id`, `x-bf16-model`, rate-limit headers, and optional `x-bf16-cost-usd` when `X-BF16-Include-Cost: true` is sent — plus 24-hour transactional `Idempotency-Key` protection so network retries never double-bill.

指令預設顯示 $BF16_API_KEY。登入並建立金鑰後會自動填入你的真實金鑰。

一鍵快速配置

One-Command End-to-End Streaming & Cost Header Probe

Sends a live Chat Completions request with `X-BF16-Include-Cost: true` and prints both the response headers (`x-bf16-cost-usd`) and JSON body.

export BF16_API_KEY="sk-bf16-v1-..."
curl -fsSi "https://api.bf16.ai/v1/chat/completions" \
  -H "Authorization: Bearer $BF16_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-BF16-Include-Cost: true" \
  -d '{"model":"deepseek/deepseek-v4.1-flash-uncensored","messages":[{"role":"user","content":"Say ok."}],"max_tokens":16}'
  1. 1

    發送一筆測試請求

    curl https://api.bf16.ai/v1/models -H "Authorization: Bearer $BF16_API_KEY"
  2. 2

    OpenAI SDK

    將 base_url 設為 https://api.bf16.ai/v1、api_key 設為你的 bf16 金鑰,其餘程式碼無須更動。

    import OpenAI from 'openai';
    
    const client = new OpenAI({
      baseURL: 'https://api.bf16.ai/v1',
      apiKey: process.env.BF16_API_KEY, // sk-bf16-v1-...
    });
    
    const res = await client.chat.completions.create({
      model: 'zai-org/glm-5.3-uncensored',
      messages: [{ role: 'user', content: 'Say ok.' }],
    });
  3. 3

    Anthropic SDK

    將 base_url 設為 https://api.bf16.ai(不加 /v1),並以 x-api-key 或 Bearer 傳入金鑰。

    import Anthropic from '@anthropic-ai/sdk';
    
    const anthropic = new Anthropic({
      baseURL: 'https://api.bf16.ai', // no /v1
      apiKey: process.env.BF16_API_KEY, // sk-bf16-v1-...
    });
    
    const msg = await anthropic.messages.create({
      model: 'zai-org/glm-5.3-uncensored',
      max_tokens: 1024,
      messages: [{ role: 'user', content: 'Say ok.' }],
    });
api.bf16.ai — Multi-Protocol Wire Contract
介面與設定檔欄位對照
Bearer sk-bf16-v1-* · Zero Session Cookies · ZDR

關鍵參數核對清單

OpenAI SDK / Vercel AI SDK baseURL
https://api.bf16.ai/v1
Anthropic SDK baseURL
https://api.bf16.ai

No /v1 — @anthropic-ai/sdk appends /v1/messages.

Cost & Guard Headers
X-BF16-Include-Cost: true · X-BF16-Max-Price-Per-M-Output · Idempotency-Key
Commercial SaaS builders: pass `user` (OpenAI) or `metadata.user_id` (Anthropic) to isolate downstream sub-users cleanly.

推薦模型分層配置

架構規劃使用旗艦模型,高頻子任務與螢幕截圖使用 Flash 模型以節省開銷。

工作流角色模型 ID選型說明USD / 1M Tokens
High-Throughput API, Vision & JSON Extractiondeepseek/deepseek-v4.1-flash-uncensoredFastest TTFT and lowest per-token rate with full 1M context + Vision + JSON Schema.$0.26 in / $0.045 cached / $1.00 out
Complex Code, Reasoning & Tool Loopszai-org/glm-5.3-uncensoredFlagship multi-turn tool calling across both OpenAI and Anthropic SDKs.$1.35 in / $0.25 cached / $4.20 out
2.8T Multimodal Flagshipmoonshotai/kimi-k3.1-pro-uncensoredMaximum creative, multilingual, and visual depth across 1M tokens.$1.95 in / $0.28 cached / $6.90 out

如何確認設定成功

  • 回應內容中包含你在 /models 目錄看到的模型 ID。

生產環境護欄與預算隔離

  • Attach an `Idempotency-Key` header (8–128 visible ASCII chars) on non-idempotent background jobs so network timeouts never trigger duplicate inference.
  • Keep `sk-bf16-v1-*` keys strictly server-side in production apps.

常見錯誤

現象
Anthropic SDK 回傳 404。
原因
基礎網址多了 /v1,導致 SDK 重複附加路徑。
解法
請使用 https://api.bf16.ai。