> ## Documentation Index
> Fetch the complete documentation index at: https://omnirelay.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 对话补全

> 调用已开通的文本模型，获得普通 JSON 或兼容 OpenAI 的流式响应。

`POST /v1/chat/completions` 接受 OpenAI 对话格式。使用 OmniRelay API Key，SDK Base URL 为 `https://api.omnirelay.ai/v1`。先查询[模型列表](https://omnirelay.ai/docs/cn/llms/listing-models.md)：公开目录展示不代表已获得调用权限。

## 普通调用

以下示例使用 `gpt-6-luna`，要求自己的列表包含它且 `mode: live`。SDK 完整初始化见[首次 API 调用](https://omnirelay.ai/docs/cn/quickstart/first-api-call.md)。

```bash cURL theme={null}
curl -i https://api.omnirelay.ai/v1/chat/completions \
  -H "Authorization: Bearer $OMNIRELAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-6-luna","messages":[{"role":"user","content":"你好 OmniRelay"}],"max_completion_tokens":64}'
```

```python Python theme={null}
response = client.chat.completions.create(
    model="gpt-6-luna",
    messages=[{"role": "user", "content": "你好 OmniRelay"}],
    max_completion_tokens=64,
)
print(response.choices[0].message.content)
print(response.usage)
```

```javascript JavaScript theme={null}
const response = await client.chat.completions.create({
  model: "gpt-6-luna",
  messages: [{ role: "user", content: "你好 OmniRelay" }],
  max_completion_tokens: 64,
});
console.log(response.choices[0].message.content);
console.log(response.usage);
```

## 参数与能力

| 字段 | 真实文本模型规则 |
| - | - |
| `model` | 使用 `GET /v1/models` 返回的精确调用 ID，不能用显示名称替代。 |
| `messages` | 1–2,000 条文本消息；`system`、`developer` 需对应能力支持。单个文本值最多 1,048,576 字符，请求体最多 4 MiB；模型上下文窗口仍然适用。 |
| `max_tokens` / `max_completion_tokens` | 正整数，两者只能传一个。网关按模型要求转换字段。上限与默认值分别读取 `limits.output_tokens`、`limits.default_output_tokens`；GPT 示例用 `max_completion_tokens`，其他文本模型示例用 `max_tokens`。 |
| `stream` | 不传即为 `false`（返回一个 JSON 响应）。`capabilities.stream` 为 true 时推荐传 `true`，Agent 和较长的生成尤其如此。 |
| `stream_options.include_usage` | 配合 `stream: true`，请求最后一个 choices 为空的块，包含 `usage` 和已结算的 `cost_microusd`。 |
| `reasoning_effort` | 参考文档建议 `reasoning_efforts`；普通取值透传并由模型服务方判断。配置了 `default_reasoning_effort` 时，省略使用该默认值。 |
| `tags` | 可选请求标签，见[标签](https://omnirelay.ai/docs/cn/general/tags.md)。 |

多数已接入文本模型最多输出 128,000 Token、默认 32,000（Gemini 3.1 Pro Preview 和 Gemini 3.6 Flash 最多 65,536）；DeepSeek V4 Pro、GLM 5.3 和 Kimi K3 默认且最多 4,096；GPT 5.4 Mini 默认 64、最多 256。以自己列表中的逐模型限制为准。

GPT 路由按文档开放函数工具（strict/named/parallel）、JSON object/schema 与 Responses；Astra 的工具仅通过 Responses 使用。采样、推理与工具组合按模型匹配，视觉尚未接入计费合同。`tool_choice` 可传 `auto`、`none`、`required`；指定函数名还要求 `capabilities.named_tool_choice`。普通 JSON HTTP 响应**不等于**结构化 JSON 生成。不支持的字段返回 `400 unsupported_parameter`；真实参数值不合法返回 `400 invalid_parameter`。

## GPT 5.6 Sol 参数支持

`gpt-5.6-sol` 支持文本、system/developer 消息、函数工具（严格定义、指定函数与并行调用）、JSON object 和严格 JSON Schema 输出。Chat 接受 `reasoning_effort: none | low | medium | high | xhigh`；省略时默认 `none`。携带工具定义或工具结果历史时，Chat 必须使用 `none`。工具与推理组合或 `max` 强度请使用 [Responses](https://omnirelay.ai/docs/cn/llms/native-protocols.md)。

`temperature`（0–2）和 `top_p`（0–1）建议在 `none` 推理时使用；组合限制由模型服务方判断：模型服务方可能拒绝（可定位的拒绝通过 `error.param` 标明字段），也可能忽略该字段并正常返回。新增组合按模型公开文档接入，逐项真实调用验证尚待完成。查询自己的模型列表中的 `sampling_parameters`、`sampling_reasoning_efforts`、`chat_tools_reasoning_efforts` 和 `responses_reasoning_efforts`。`null` 表示没有额外推理强度限制；空参数／强度列表表示不支持。

最简请求无需额外参数：

```json theme={null}
{"model":"gpt-5.6-sol","messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"Reply with exactly: OK."}]}
```

未设置输出上限时默认 32,000 Token（DeepSeek V4 Pro、GLM 5.3 和 Kimi K3 为 4,096；GPT 5.4 Mini 为 64）；最大值为各模型的 `limits.output_tokens`，包含推理 Token。较长推理任务需明确设置上限。JSON Schema 关键字由模型服务方判断。

## 响应与推理内容

成功 JSON 响应包含 `choices[0].message.content`、`usage` 和 `cost_microusd`。费用单位为微美元，除以 1,000,000 得到美元。

当 `capabilities.reasoning_content` 为 true 时，可选推理文本还会出现在 `choices[0].message.reasoning_content`。这与是否接受 `reasoning_effort` 是两回事：能展示推理内容不代表可以关闭或调整推理。当前 DeepSeek V4 Pro 和 GLM 5.3 可返回此字段。省略推理明细计数不会让 completion Token 从计费中消失。

保存响应头 `X-Request-ID`，联系支持时凭它定位调用。可选[请求元数据](https://omnirelay.ai/docs/cn/llms/request-metadata.md)提供额外路由信息。

## 流式输出

开启 SSE 前检查 `capabilities.stream`。成功流以 `data: [DONE]` 结束；最后一个 choices 块含结束原因，例如 `stop` 或 `length`。用量块的 choices 为空，需单独处理。

```python Python theme={null}
# 仅在自己的列表包含此 ID 且支持 stream 时使用。
stream = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[{"role": "user", "content": "你好 OmniRelay"}],
    max_tokens=128,
    stream=True,
    stream_options={"include_usage": True},
)
for chunk in stream:
    if chunk.choices:
        delta = chunk.choices[0].delta
        reasoning = getattr(delta, "reasoning_content", None)
        if reasoning:
            print(reasoning, end="", flush=True)
        if delta.content:
            print(delta.content, end="", flush=True)
    if chunk.usage:
        print("Usage:", chunk.usage)
        print("Cost (micro-USD):", getattr(chunk, "cost_microusd", None))
```

支持时，流式推理文本位于 `choices[0].delta.reasoning_content`。即使客户未要求用量块，网关也收集最终用量。

> [!WARNING]
>
> 关闭 SDK 自动重试。超时、错误事件或缺少 `[DONE]` 可能让真实费用停留在待对账状态；发起另一笔付费调用前，先按错误码判断本次是否收费。流开始时的 HTTP 200 不能单独证明成功。详见[用量与计费](https://omnirelay.ai/docs/cn/general/usage-billing.md)和[错误处理](https://omnirelay.ai/docs/cn/general/errors.md)。

完整 schema 见[创建对话补全](https://omnirelay.ai/docs/cn/api-reference/chat/create-chat-completion.md)。

## 全部可调用模型的能力匹配

每个可调用模型入口（含折扣别名）均有独立合同。按自己的 `/v1/models` 响应选择参数；文档确认的能力正常转发，平台必须保护的预算／协议边界仍校验。新增参数组合属于文档接入，尚待逐项真实调用验收。

| 模型入口 | 文档接入能力与组合限制 |
| - | - |
| GPT 5.4 Mini | 函数工具、strict/named/parallel、JSON object/schema、Responses、none/low/medium/high/xhigh；采样仅 none。 |
| GPT 5.6 Sol/Terra/Luna，GPT 6 Sol/Luna | 同上；Chat 工具仅 none；Responses 可组合工具与推理并支持 max。 |
| GPT 6 Astra | Chat 文本与 JSON；工具使用 Responses；推理 low/medium/high/xhigh，Responses 再支持 max；不接受 none 与采样。 |
| Claude 全部普通与 sale/ 入口 | 兼容函数工具、指定函数、并行调用、developer、temperature/top\_p、stop；兼容层明确忽略的 strict 与 response\_format 不宣传为保证。 |
| DeepSeek V4 Pro | 函数工具、JSON object、temperature/top\_p、stop、assistant reasoning\_content 回传；thinking enabled/disabled，文档推理强度及兼容别名；required/指定函数仅在关闭推理时可用；采样在推理模式下可能被模型忽略。 |
| GLM 5.3 | 函数工具、tool\_choice:auto、JSON object、tool\_stream、推理历史、temperature/top\_p；thinking 仅 enabled，推理 low/high/max。 |
| Gemini 3.1 Pro Preview、Gemini 3.6 Flash、Kimi K3 | 已实测 system/user 文本与 SSE；工具、JSON 模式和采样尚未审阅，不作宣传；其他字段仍透传，由模型服务方判断。 |

客户端回传 DeepSeek 工具对话时保留 assistant 的 `reasoning_content`。查阅 `tool_choice_values`、`tool_choice_reasoning_efforts`、`thinking_modes` 和 `parameter_ranges`；Claude/GLM temperature 最高 1，GLM top\_p 最低 0.01。普通可选参数的 null 透传并由模型服务方判断；空工具列表可传。多候选生成、额外付费服务、托管工具、图片／音频仍需要各自可结算的协议合同。

## 参数透传

全部可调用模型使用 `parameter_policy: upstream-first`。能力表是文档建议，普通参数不因本地能力标志为 false、推理值未列出或 Schema 关键字新增而提前拒绝；字段与组合是否合法交由模型服务方判断。函数工具的定义、legacy functions、推理历史、普通扩展字段及 Schema 原样保留；不静默删掉采样参数，也不自动改变推理强度或调用协议。部分模型会忽略不支持的字段而不报错，因此成功返回不代表可选字段已生效；请以能力列表判断支持情况。

平台仍核对模型权限、鉴权、请求体大小、输出预算和费用预留；多候选、收费 service\_tier、pro 推理、托管工具、媒体、持久化与后台状态尚无对应结算合同。输出上限三种常见字段统一处理，省略时注入默认上限；未设置推理且未设置 thinking 时使用模型默认强度。JSON 与流的普通响应扩展字段保留，最终费用取 OmniRelay 结算值。模型服务方 400／422 拒绝释放预留、不收费；模型服务方故障（5xx）、超时或断流仍待对账。新增参数组合未逐项付费验证。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.