聊天 API

Chat completions

主端点。 GPT-5.5, Claude Sonnet 5, Gemini 3 Flash 以及下方所有其他聊天模型——请求体完全相同。

POSThttps://api.oxyy.ai/v1/chat/completions

参数

参数类型必填描述
modelstring必填A model id from GET /v1/models, e.g. gpt-5.5, claude-sonnet-5, gemini-3-flash.
modelsarray可选当 model 失败时按顺序尝试的备用模型 ID。见下方。
messagesarray必填对话。每个项目都有一个 role 和 content;content 可以是字符串或 content parts 数组。 角色:systemdeveloperuserassistanttoolfunction
temperaturenumber可选采样温度,0–2。数值越高,随机性越强。 默认 the provider's own
max_tokensinteger可选最大生成 token 数,≥ 1。 默认 the provider's own, or the model's default output limit where the provider requires a value
top_pnumber可选核采样,0–1。使用此参数或 temperature 之一,切勿同时使用。
top_kinteger可选从最可能的 k 个 token 中采样。将转发给支持该参数的提供商。
ninteger可选要生成的补全数量,1–128。每个选项都要计费。 默认 1
streamboolean可选以 server-sent events 形式流式传输回复。请参阅 流式传输。 默认 false
stream_optionsobject可选{include_usage: true} 会添加一个包含 token 计数和 cost 的最终数据块。
stopstring|array可选最多四个停止生成内容的序列。
seedinteger可选在支持的提供商上尽力实现确定性。
frequency_penaltynumber可选-2 至 2。根据出现频率惩罚重复的 token。 默认 0
presence_penaltynumber可选-2 至 2。惩罚重复使用任何已出现的 token。 默认 0
toolsarray可选函数声明。请参阅 工具调用。
tool_choicestring|object可选以下之一:noneautorequired{type:"function",…} 默认 auto
parallel_tool_callsboolean可选允许在一轮中进行多次工具调用。 默认 true
response_formatobject可选强制输出 JSON。请参阅 结构化输出。 类型:textjson_objectjson_schema
reasoning_effortstring可选推理模型的思考程度;none 在支持的模型上关闭思考。若模型的级别已知,则映射到模型使用的对应级别(有时为更高水平或关闭;当有差异时,dropped_params 会标出使用的级别)。请参阅 推理。 以下之一:noneminimallowmediumhighxhighmax
logprobsboolean可选返回所选 token 的对数概率。
top_logprobsinteger可选每个位置报告的候选数。需要 logprobs。
logit_biasobject可选Token ID 到偏置的映射,-100–100。
userstring可选你自己的最终用户的稳定 ID。帮助你归因使用量。
modalitiesarray可选模型应返回的内容。使用 ["image","text"] 让图片模型通过聊天回答。 以下之一:textimageaudio
image_configobject可选当模型用图片回答时的图片控制:{image_size, aspect_ratio}。
service_tierstring可选转发给提供层级的服务商,并在响应中回传。
metadataobject可选随请求携带的不透明键/值对。
您自己的回退模型。 发送 models: ["a", "b"] 旁边 model (OpenRouter 字段)。在 chat 以及 image、audio、video 和 embedding 端点上,请求会转发至 a,然后 b,当每一个提供商 model (及其自身的备用链)失败。如果没有 model,第一个条目是模型。除了 model(重复项和 model 本身会被忽略);更多内容是一个 400,非常规模型 ID 项也是如此 (error.param 为其命名,例如 models[1])。每个 id 必须是你的 key 和层级(tier)可以调用且与 model; 未知或禁用的会被直接拒绝(error.param 为 models) 继续对话。此时不可用的备用模型会被跳过。每个备用模型会为请求的预算增加一次 provider 尝试(默认 5 次,最多 14 次)。预算按顺序消耗,而不是按模型预留,因此如果某个模型的 provider 依次失败,可能会在轮到你的列表之前就把预算耗尽。异步任务(图片或语音,带 async: true,且视频除非发送 sync: true) 运行于 model 单独:指定了 models 将被拒绝,错误码为 400 unsupported_parameter; 同步发送以按顺序尝试列表。您将按实际回答的模型及其自身价格付费。

代码示例

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["OXYY_API_KEY"],
    base_url="https://api.oxyy.ai/v1"
)

response = client.chat.completions.create(
    model="claude-sonnet-5",
    messages=[
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": "Explain HTTP caching in two sentences."},
    ],
    temperature=0.7,
    max_tokens=4096
)

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

const client = new OpenAI({
  apiKey: process.env.OXYY_API_KEY,
  baseURL: 'https://api.oxyy.ai/v1'
});

const response = await client.chat.completions.create({
  model: 'claude-sonnet-5',
  messages: [
    { role: 'system', content: 'You are a concise assistant.' },
    { role: 'user', content: 'Explain HTTP caching in two sentences.' },
  ],
  temperature: 0.7,
  max_tokens: 4096
});

console.log(response.choices[0].message.content);
curl https://api.oxyy.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OXYY_API_KEY" \
  -d '{
    "model": "claude-sonnet-5",
    "messages": [{"role": "user", "content": "Explain HTTP caching."}],
    "temperature": 0.7,
    "max_tokens": 4096
  }'
// composer require openai-php/client
$client = OpenAI::factory()
    ->withApiKey(getenv('OXYY_API_KEY'))
    ->withBaseUri('https://api.oxyy.ai/v1')
    ->make();

$response = $client->chat()->create([
    'model' => 'claude-sonnet-5',
    'messages' => [['role' => 'user', 'content' => 'Hello!']],
    'temperature' => 0.7,
]);

echo $response->choices[0]->message->content;
// go get github.com/sashabaranov/go-openai
cfg := openai.DefaultConfig(os.Getenv("OXYY_API_KEY"))
cfg.BaseURL = "https://api.oxyy.ai/v1"
client := openai.NewClientWithConfig(cfg)

resp, err := client.CreateChatCompletion(context.Background(), openai.ChatCompletionRequest{
    Model: "claude-sonnet-5",
    Messages: []openai.ChatCompletionMessage{
        {Role: openai.ChatMessageRoleUser, Content: "Hello!"},
    },
})

响应示例

响应
{
  "id": "chatcmpl-abc123def456",
  "object": "chat.completion",
  "created": 1700000000,
  "model": "claude-sonnet-5",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I help you today?",
        "refusal": null
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 9,
    "total_tokens": 21,
    "prompt_tokens_details": {
      "cached_tokens": 0,
      "cache_write_tokens": 0,
      "text_tokens": 12,
      "image_tokens": null,
      "audio_tokens": null
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0,
      "text_tokens": 9,
      "audio_tokens": null
    },
    "is_byok": false,
    "cost": 0.000106,
    "cost_details": { "currency": "USD", "input": 0.000036, "output": 0.00007 }
  }
}

finish_reason 属于 stop, length, tool_calls, content_filter 或 function_call. 当提供商报告其自身的内容时,它会作为其旁边传递 native_finish_reason. 通过聊天回复的图片会到达 message.images.

Batch API

从单个文件处理多次对话补全,适用于不需要立即得到回答的工作。其格式与 OpenAI 一致,因此 client.batches.create, retrieve, list 与 cancel 可直接无缝使用。网关通过与实时请求相同的管道,自行运行每一行代码。

POSThttps://api.oxyy.ai/v1/filesthe input, purpose=batch
POSThttps://api.oxyy.ai/v1/batches
GEThttps://api.oxyy.ai/v1/batches最新的排在前面;limit, after
GEThttps://api.oxyy.ai/v1/batches/{id}
POSThttps://api.oxyy.ai/v1/batches/{id}/cancel
GEThttps://api.oxyy.ai/v1/files/{id}/content结果
步骤详细信息
输入文件上传到 POST /v1/files 的 JSONL,purpose=batch,每行一个请求:{"custom_id": "…", "method": "POST", "url": "/v1/chat/completions", "body": {…}}。每个 custom_id 在文件中必须是唯一的,且拒绝 stream: true。最多 50,000 行;文件受 Files API 上传限制。
创建使用 input_file_id、endpoint: "/v1/chat/completions"、completion_window: "24h"(唯一的时间窗口)以及可选的 metadata(最多 16 个字符串键值对)的 POST /v1/batches。使用 API key 创建:每一行都以此 key 运行,具有相应的权限范围、模型列表和限制。每个账户最多 5 个未完成的批处理;再多一个将返回 429 batch_limit_exceeded。
端点仅限 /v1/chat/completions。/v1/responses、/v1/embeddings、/v1/completions 和 /v1/moderations 将被拒绝并返回 400。
状态validating、in_progress、finalizing,然后是 completed。包含无效行的文件会以 failed 结束,其 errors 会指出具体行号;率先到期的 24 小时窗口会显示为 expired;取消操作会显示为 cancelling,然后是 cancelled。request_counts 和 usage 显示进度。
结果批处理结束时,output_file_id 会为每个成功的行保存一条记录,error_file_id 会为每个失败的行保存一条记录,采用 OpenAI 的格式:{"id": "batch_req_…", "custom_id", "response": {"status_code", "request_id", "body"}, "error"}。使用 client.files.content 下载它们并通过 custom_id 进行匹配。它们是 Files API 文件(用途为 batch_output):它们计入你的文件存储额度,并像其他文件一样过期。
无答案的行因错误而应答的请求与其 response 一起记录在错误文件中。无此项的行包含 response: null 和 error.code:batch_expired(窗口在运行前已结束)或 batch_line_interrupted(网关重启时正在运行;它可能已经运行并已被计费,因此绝不会再次运行——若仍需使用,请将其放入新的 batch 中)。
账单当批处理任务运行时,每一行的计费方式与实时请求完全相同。没有批处理折扣,且创建批处理不收取任何费用。
速率批处理与实时流量共享速率限制和并发,且批处理会为实时调用保留至少一半的配额,因此其运行速度最多约为你当前等级每分钟请求数的一半。因速率限制或临时服务器错误而被拒绝的行会在稍后重试。
取消停止新行。已在运行的行会执行完毕并计费,其结果也会保留;从未启动的行将不会产生记录。

可用模型

57 models
模型
Model ID