整合指南
OpenAI SDK(任意語言)
通用配方——換掉 Base URL,其餘照舊。
任何 OpenAI 相容用戶端只需改兩個值即可使用 Linkex:Base URL 與 API Key。適用於官方 OpenAI SDK、LangChain、LlamaIndex、Vercel AI SDK 及多數 Agent 框架。
配方
| 設定 | 值 |
|---|---|
| Base URL | https://linkex.ai/v1 |
| API Key | 你的 Linkex sk-... Key |
| 模型 | linkex.ai/pricing 上的任意 id |
from openai import OpenAI
client = OpenAI(base_url="https://linkex.ai/v1", api_key="sk-YOUR_KEY")
# 串流照常可用
stream = client.chat.completions.create(
model="claude-sonnet-4-5",
messages=[{"role": "user", "content": "Stream me a haiku"}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://linkex.ai/v1',
apiKey: process.env.LINKEX_API_KEY,
});
const stream = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Stream me a haiku' }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}import (
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
client := openai.NewClient(
option.WithBaseURL("https://linkex.ai/v1"),
option.WithAPIKey(os.Getenv("LINKEX_API_KEY")),
)from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
base_url="https://linkex.ai/v1",
api_key="sk-YOUR_KEY",
model="gemini-2.5-pro",
)import { createOpenAI } from '@ai-sdk/openai';
const linkex = createOpenAI({
baseURL: 'https://linkex.ai/v1',
apiKey: process.env.LINKEX_API_KEY,
});
const model = linkex('claude-sonnet-4-5');其他請求格式
除 OpenAI 格式外,同一把 Key 也可認證:
- Anthropic Messages——
POST https://linkex.ai/v1/messages(見 Claude Code) - Gemini——
https://linkex.ai/v1beta/models/...
常見錯誤
| HTTP | 原因 | 處理 |
|---|---|---|
| 401 | Key 錯誤或已停用 | 在控制台 → Keys 重建 Key;檢查 Bearer 前綴 |
| 403 | 模型未對你的 Token/群組開放 | 檢查 Key 的模型限制設定 |
| 429 | 觸發速率限制 | 退避重試;per-key 限制保護共享帳戶 |
| 餘額不足錯誤 | 餘額用盡 | 充值 |
| 模型 404 | 模型 id 錯誤 | 從 GET /v1/models 或定價頁複製精確 id |