> ## 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.

# 首次 API 调用

> 查询自己的可用模型，使用 OmniRelay Key 发起真实文本调用。

## 1. 确认服务已开通

登录[控制台](https://omnirelay.ai/login)，确认邮箱和工作空间，在**总览 → 真实模型服务**查看开通状态。未开通时可使用页面提供的「申请开通」。验证后的新账户在自动开通启用时进入配置队列；开通前也可以浏览**模型广场**，此时所有模型均标记为不可用且没有调用入口。充值或账户配置完成本身不等于推理就绪，需要核查时联系 [support@omnirelay.ai](mailto:support@omnirelay.ai)。

## 2. 创建 API Key

确认开通完成后，在 **API Keys** 创建独立 Key（未开通时入口禁用），设置所需模型范围、预算和到期时间。完整值在创建或轮换时显示，之后可在确认身份后再次查看；请保存在服务端。客户仅需 OmniRelay Key，无需其他凭证。

```bash theme={null}
export OMNIRELAY_API_KEY="YOUR_OMNIRELAY_API_KEY"
export OMNIRELAY_BASE_URL="https://api.omnirelay.ai/v1"
```

## 3. 查询可用模型

先查询自己的列表。以下调用示例使用 `gpt-6-luna`，只在列表含它且 `mode: live` 时适用。空列表时检查开通状态和 Key 模型限制。

```bash theme={null}
curl "$OMNIRELAY_BASE_URL/models" \
  -H "Authorization: Bearer $OMNIRELAY_API_KEY"
```

## 4. 发送文本请求

推荐默认使用流式：内容边生成边返回，较长的生成也不会因非流式整次返回的时限而中断。不传 `stream` 时返回一个完整的 JSON 响应。

```bash cURL theme={null}
curl -N "$OMNIRELAY_BASE_URL/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":1024,"stream":true,"stream_options":{"include_usage":true}}'
```

```python Python theme={null}
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["OMNIRELAY_API_KEY"],
    base_url=os.environ["OMNIRELAY_BASE_URL"],
    max_retries=0,
)
stream = client.chat.completions.create(
    model="gpt-6-luna",
    messages=[{"role": "user", "content": "你好 OmniRelay"}],
    max_completion_tokens=1024,
    stream=True,
    stream_options={"include_usage": True},
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
    # 用量和费用在最后一个没有 choices 的分块里。
    if chunk.usage:
        print("\n", chunk.usage, getattr(chunk, "cost_microusd", None))
```

```javascript JavaScript theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.OMNIRELAY_API_KEY,
  baseURL: process.env.OMNIRELAY_BASE_URL,
  maxRetries: 0,
});
const stream = await client.chat.completions.create({
  model: "gpt-6-luna",
  messages: [{ role: "user", content: "你好 OmniRelay" }],
  max_completion_tokens: 1024,
  stream: true,
  stream_options: { include_usage: true },
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
  // 用量和费用在最后一个没有 choices 的分块里。
  if (chunk.usage) console.log("\n", chunk.usage, chunk.cost_microusd);
}
```

## 5. 查看结果与费用

请保存响应头 `X-Request-ID`：支持人员凭它定位单次调用，**用量日志**页面显示汇总。`usage` 是已验证用量，`cost_microusd` 是实际扣费（除以 1,000,000 得到美元），与调用前的最高费用预留不同。

GPT 6 Luna 上下文 1,050,000 Token，默认输出 32,000、最多 128,000 Token。多数已接入文本模型最多输出 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。切换模型时检查 `limits`、`capabilities.stream` 和 `reasoning_efforts`，不要把 GPT 参数照搬到其他模型。真实请求不要传 `locale` 或不支持的字段。发送函数工具或 JSON 格式前，先核对 `capabilities.tools`、`json_object` 和 `json_schema`。

> [!WARNING]
>
> 真实调用会收费，并在发送前预留费用；短提示词也需要足够余额和预算。SDK 示例已关闭自动重试。超时或断流后先查记录，不要直接重发。

[对话补全](https://omnirelay.ai/docs/cn/llms/chat-completions.md) · [模型列表](https://omnirelay.ai/docs/cn/llms/listing-models.md) · [用量与计费](https://omnirelay.ai/docs/cn/general/usage-billing.md) · [用户手册](https://omnirelay.ai/docs/cn/user-manual.md)


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