S
SwiftAPI

API 接入文档

SwiftAPI 提供与 OpenAI 完全兼容的接口规范。您可以使用官方的 OpenAI SDK 或任何支持自定义 Base URL 的开源客户端来接入我们的服务。

快速开始

要使用我们的 API,您只需要修改两处配置:

  • Base URL 更改为 https://api.hellonb.top/v1
  • API Key 更改为您在控制台生成的令牌

Python SDK 示例

python
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-key",
    base_url="https://api.hellonb.top/v1"
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "user", "content": "Hello!"}
    ]
)
print(response.choices[0].message.content)

认证方式

所有 API 请求必须在 HTTP Header 中携带 Authorization 字段进行 Bearer Token 认证。

http
Authorization: Bearer sk-your-key

Chat Completions

用于生成文本对话回复,支持流式输出 (SSE)。

POST/v1/chat/completions

请求示例 (cURL)

bash
curl https://api.hellonb.top/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $SWIFTAPI_KEY" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Who are you?"}
    ],
    "stream": false
  }'

计费说明:模型计费单位为人民币元,例如 gpt-4o 模型输入价格为 ¥22/百万tokens,输出价格为 ¥88/百万tokens。

查询余额

用于查询当前 API Key 关联账户的可用余额。

GET/v1/dashboard/billing/subscription

返回示例

json
{
  "object": "billing_subscription",
  "has_payment_method": false,
  "canceled": false,
  "canceled_at": null,
  "delinquent": null,
  "access_until": 1999999999,
  "soft_limit": 0,
  "hard_limit": 128.50,
  "system_hard_limit": 128.50,
  "soft_limit_usd": 0,
  "hard_limit_usd": 128.50,
  "system_hard_limit_usd": 128.50,
  "plan": {
    "title": "Pay-as-you-go",
    "id": "pay-as-you-go"
  },
  "account_name": "User",
  "po_number": null,
  "billing_email": null,
  "tax_ids": null,
  "billing_address": null,
  "business_address": null
}

其中 hard_limit_usd 字段表示您的当前余额为 ¥128.50(为兼容客户端,字段名保留带 usd,但实际单位为人民币元)。

错误码说明

HTTP 状态码说明处理建议
400请求格式错误或触发敏感词拦截检查请求体 JSON 格式及内容
401API Key 无效或未提供检查 Key 拼写是否正确
402余额不足请前往控制台充值
429触发速率限制 (Rate Limit)降低并发请求频率
502/503上游通道全部拥堵或不可用稍后重试或联系管理员