Documentation Index
Fetch the complete documentation index at: https://docs.focusapi.cn/llms.txt
Use this file to discover all available pages before exploring further.
本页是 最重要的入门路径:完成后再阅读 模型说明 与 对话 API。
- 已有 FocusAPI 公有云账号
- 已在控制台创建 API Key(
sk- 开头)
1. 确认 Base URL
FocusAPI 兼容 OpenAI API v1 路径,默认 Base URL 为:
https://api.FocusAPI.com/v1
若控制台或公告提供了区域/专线地址,以控制台显示为准。
2. 用 curl 测试(推荐)
将 sk-your-api-key 替换为你的真实 Key:
curl https://api.FocusAPI.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-api-key" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{"role": "user", "content": "用一句话介绍 FocusAPI"}
]
}'
成功时
你会收到 JSON,其中包含 choices[0].message.content 等字段,HTTP 状态码为 200。
常见失败
| 现象 | 可能原因 | 处理 |
|---|
401 | Key 无效或未传 | 见 401 未授权 |
429 | 触发限流 | 见 429 限流 |
model not found | 模型名错误或账号无权限 | 在控制台「模型广场」核对可用 model |
长时间无响应后 524 | 上游超时 | 见 524 超时 |
3. 使用 OpenAI 官方 SDK(Python)
安装 SDK 后,只需修改 base_url 与 api_key:
from openai import OpenAI
client = OpenAI(
base_url="https://api.FocusAPI.com/v1",
api_key="sk-your-api-key",
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "user", "content": "Hello from FocusAPI"},
],
)
print(response.choices[0].message.content)
4. 使用 OpenAI 官方 SDK(Node.js)
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.FocusAPI.com/v1",
apiKey: "sk-your-api-key",
});
const response = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Hello from FocusAPI" }],
});
console.log(response.choices[0]?.message?.content);
5. 流式输出(可选)
在请求体中设置 "stream": true,SDK 与 curl 需按流式方式读取 SSE。细节见 对话 API。
下一步