无界计算

API 文档

说明

快速开始

Base URL

https://inf.tos.run/api/v1

兼容 OpenAI SDK — 只需把 base_url 改为上面的地址,并替换为你的 API Key。

curl
curl -X POST https://inf.tos.run/api/v1/chat/completions \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-chat",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

认证

所有 API 请求需要在 Authorization header 中提供你的 API Key。

Authorization: Bearer sk-your-api-key

安全提示

切勿在前端代码中暴露 API Key,请通过环境变量在服务端调用。

模型列表

获取所有主流模型的列表。

GET /v1/models
curl https://inf.tos.run/api/v1/models \
  -H "Authorization: Bearer sk-your-api-key"
响应
{
  "object": "list",
  "data": [
    {
      "id": "deepseek-chat",
      "object": "model",
      "owned_by": "deepseek"
    },
    {
      "id": "gpt-4o",
      "object": "model",
      "owned_by": "openai"
    }
  ]
}

聊天补全

发送消息并获取 AI 回复,兼容 OpenAI API 格式。

POST /v1/chat/completions
curl -X POST https://inf.tos.run/api/v1/chat/completions \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "deepseek-chat",
  "messages": [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "What is the capital of France?"}
  ],
  "temperature": 0.7,
  "max_tokens": 1024,
  "stream": false
}'
响应
{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "model": "deepseek-chat",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The capital of France is Paris."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 8,
    "total_tokens": 33
  }
}

流式输出

设置 stream: true 以获取流式响应。

流式请求
curl -X POST https://inf.tos.run/api/v1/chat/completions \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "deepseek-chat",
  "messages": [{"role": "user", "content": "Tell me a joke"}],
  "stream": true
}'
流式事件
data: {"id":"chatcmpl-...","choices":[{"delta":{"role":"assistant"},"index":0}]}

data: {"id":"chatcmpl-...","choices":[{"delta":{"content":"Why"},"index":0}]}

data: {"id":"chatcmpl-...","choices":[{"delta":{"content":" did"},"index":0}]}

data: [DONE]

错误码

HTTP 状态码错误说明
401UnauthorizedAPI Key 无效或缺失
402Payment Required付费模型额度不足
429Too Many Requests超过速率限制(RPM 或 RPD)
400Bad Request请求体或参数不合法
500Internal Error上游模型服务异常或服务端错误

速率限制

每个 API Key 默认限制:20 RPM / 50 RPD。响应 Header 中包含速率限制信息。

响应 Header说明
X-RateLimit-Remaining-RPM当前分钟剩余可用请求数
X-RateLimit-Remaining-RPD当日剩余可用请求数
Retry-After收到 429 时,等待几秒后再重试

代码示例

Python (OpenAI SDK)
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-api-key",
    base_url="https://inf.tos.run/api/v1"
)

response = client.chat.completions.create(
    model="deepseek-chat",
    messages=[
        {"role": "user", "content": "Hello!"}
    ]
)

print(response.choices[0].message.content)
JavaScript (Node.js)
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'sk-your-api-key',
  baseURL: 'https://inf.tos.run/api/v1',
});

const response = await client.chat.completions.create({
  model: 'deepseek-chat',
  messages: [{ role: 'user', content: 'Hello!' }],
});

console.log(response.choices[0].message.content);
Python (Streaming)
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-api-key",
    base_url="https://inf.tos.run/api/v1"
)

stream = client.chat.completions.create(
    model="deepseek-chat",
    messages=[{"role": "user", "content": "Tell me a story"}],
    stream=True
)

for chunk in stream:
    content = chunk.choices[0].delta.content
    if content:
        print(content, end="", flush=True)
curl
curl -X POST https://inf.tos.run/api/v1/chat/completions \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Explain quantum computing in simple terms."}
    ],
    "temperature": 0.7,
    "max_tokens": 512
  }'