DOCS / OPENAI COMPATIBLE

接入,不绕路。 Connect, without detours.

把 Base URL、密钥和模型 ID 填进已有客户端。YUAPI 负责协议转换、路由与重试,你先跑通第一条请求。 Add the Base URL, key, and model ID to the client you already use. YUAPI handles protocol translation, routing, and retries so you can get the first request working.

OpenAI /v1 SSE streaming Responses supported

快速开始Quickstart

先在控制台创建项目密钥,再把客户端指向 YUAPI。示例使用 gpt-6.1-sol,你也可以替换成模型广场中的任意完整 ID。 Create a project key in the console, then point your client at YUAPI. The example uses gpt-6.1-sol; replace it with any complete ID from the model catalog.

01

创建密钥Create a key

在控制台创建项目密钥,确认额度、模型范围和过期时间。Create a project key in the console and confirm quota, model scope, and expiry.

02

填写地址Set the endpoint

OpenAI 兼容客户端填写 https://us.nioz.cn/v1。For OpenAI-compatible clients, use https://us.nioz.cn/v1.

03

发出请求Send a request

先用短文本和流式关闭测试,跑通后再开启 SSE、工具调用或结构化输出。Test with short text and streaming off first, then enable SSE, tool calls, or structured output.

Base URL https://us.nioz.cn/v1
Authorization Bearer YOUR_YUAPI_KEY
Content-Type application/json
i
客户端会自动拼接 /v1 吗?Does your client append /v1 automatically?

先查看客户端说明。已经自动拼接 /v1 的客户端通常填写根地址,避免出现 /v1/v1。若管理员提供了其他域名,以控制台显示为准。 Check the client documentation first. Clients that already append /v1 usually need the root URL to avoid /v1/v1. If an administrator provides another hostname, use the address shown in the console.

cURL
curl https://us.nioz.cn/v1/chat/completions \
  -H "Authorization: Bearer YOUR_YUAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-6.1-sol",
    "messages": [
      { "role": "user", "content": "Hello from YUAPI" }
    ]
  }'

OpenAI 兼容调用OpenAI-compatible calls

保留原有 SDK,只替换 baseURL 与密钥。聊天补全、流式响应和工具调用的请求结构保持不变。 Keep your existing SDK and replace only baseURL and the key. Chat completions, streaming, and tool-call payloads keep the same shape.

curl https://us.nioz.cn/v1/chat/completions \
  -H "Authorization: Bearer $YUAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-6.1-sol",
    "messages": [
      { "role": "user", "content": "Summarize this release note." }
    ],
    "stream": true
  }'
↯
流式响应Streaming responses

使用 stream: true 时,服务端返回 SSE。请保留客户端原有解析逻辑,并在断开连接时停止读取。 With stream: true, the server returns SSE. Keep your existing parser and stop reading when the connection is aborted.

Claude Code 与 Codex 接入Claude Code and Codex setup

客户端版本不同,配置字段也可能不同。以下示例展示常见接入方式;模型 ID 必须来自你当前分组实际可用的列表。 Configuration fields vary by client version. The examples below show the common setup; the model ID must come from the models actually available to your current group.

Claude Code

Claude Code 使用 ANTHROPIC_BASE_URL 与 ANTHROPIC_AUTH_TOKEN。客户端会自行拼接 /v1/messages,因此地址填写根域名。 Claude Code uses ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN. The client appends /v1/messages, so use the root hostname.

npm install -g @anthropic-ai/claude-code

export ANTHROPIC_BASE_URL="https://us.nioz.cn"
export ANTHROPIC_AUTH_TOKEN="YOUR_YUAPI_KEY"
export ANTHROPIC_MODEL="YOUR_CLAUDE_MODEL_ID"
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC="1"

claude

Codex CLI

把提供商配置合并到 ~/.codex/config.toml。Windows 对应 %USERPROFILE%\.codex\config.toml,保存后重新启动 Codex。 Merge the provider configuration into ~/.codex/config.toml. On Windows this is %USERPROFILE%\.codex\config.toml. Restart Codex after saving.

config.toml
model_provider = "yuapi"
model = "gpt-6.1-sol"

[model_providers.yuapi]
name = "YUAPI"
base_url = "https://us.nioz.cn/v1"
wire_api = "responses"
env_key = "YUAPI_API_KEY"
requires_openai_auth = false
npm install -g @openai/codex
export YUAPI_API_KEY="YOUR_YUAPI_KEY"
codex --version
codex
!
模型权限以控制台为准Model access follows the console

公开目录是标准分组快照。Claude Code 需要当前分组实际提供可用的 Claude 模型;若你的分组只有 OpenAI 兼容模型,请勿把不存在的模型 ID 填入客户端。 The public catalog is a standard-group snapshot. Claude Code needs a Claude model actually available in your group. If your group only provides OpenAI-compatible models, do not put a nonexistent model ID in the client.

查询当前可用模型List available models

用实际密钥请求 /v1/models,返回结果才是当前账号与分组的权限范围。公开模型广场只用于查找 ID。 Request /v1/models with the real key. That response is the authoritative scope for your account and group; the public catalog is only for finding IDs.

models
curl https://us.nioz.cn/v1/models \
  -H "Authorization: Bearer YOUR_YUAPI_KEY"

提示:模型 ID 区分大小写与标点。复制完整 ID,不要只复制版本号。 Tip: model IDs are case- and punctuation-sensitive. Copy the complete ID, not only the version number.

错误码与排查Error codes and troubleshooting

错误响应通常包含 HTTP 状态、type、code 和 request_id。先记录 request_id,再按状态码排查。 Error responses usually include an HTTP status, type, code, and request_id. Record the request_id first, then troubleshoot by status.

HTTP 常见 codeCommon code 排查方向What to check
400 invalid_request_error JSON 格式、消息结构、参数类型或必填字段。JSON syntax, message shape, parameter types, or required fields.
401 invalid_api_key 密钥缺失、复制不完整、已过期或已被禁用。Missing, truncated, expired, or disabled key.
403 permission_error 当前密钥没有该模型、分组或接口权限。The key lacks access to the model, group, or endpoint.
404 model_not_found 模型 ID 拼写、分组权限,或地址多写/漏写 /v1。Model ID spelling, group access, or a duplicated/missing /v1.
413 request_too_large 请求体、图片或上下文超过当前限制。Body, image, or context exceeds the current limit.
429 rate_limit_error 并发或速率过高,先指数退避,再检查额度。Rate or concurrency limit hit. Back off exponentially, then check quota.
500 upstream_error 上游返回异常。记录请求 ID,稍后重试或切换模型。Upstream failure. Record the request ID, retry later, or switch models.
502 upstream_unavailable 上游暂不可达,通常可重试;持续出现请联系支持。Upstream unreachable. Usually retryable; contact support if it persists.
503 no_available_route 当前没有满足条件的路由。检查模型范围、预算或限流策略。No route satisfies the request. Check model scope, budget, or rate policy.
504 upstream_timeout 上游超时。缩短输入、增加超时或稍后重试。Upstream timeout. Shorten input, increase timeout, or retry later.

错误码可能随网关版本调整,以响应体中的 type / code 为准。 Error codes may change between gateway versions. Treat the type / code in the response as authoritative.

常见问题FAQ

应该填写哪个 Base URL?Which Base URL should I use?

OpenAI 兼容客户端使用 https://us.nioz.cn/v1。如果客户端会自动追加 /v1,请按客户端说明填写根地址;管理员提供其他域名时,以控制台为准。OpenAI-compatible clients use https://us.nioz.cn/v1. If the client appends /v1 automatically, use the root URL as instructed by the client. If an administrator provides another hostname, follow the console.

登录密码就是 API Key 吗?Is my console login credential the API key?

不是。登录密码用于控制台;API Key 在控制台单独创建,只用于客户端请求。不要把密钥提交到 Git 仓库或公开日志。No. The console login credential is separate. API keys are created in the console and used only by clients. Never commit keys to Git or public logs.

为什么模型返回 404?Why does the model return 404?

先确认模型 ID 是否完整、大小写是否正确,再检查当前密钥的分组是否包含该模型。也可以通过 /v1/models 查看实际可用列表。Check that the model ID is complete and correctly cased, then verify that the key's group includes it. You can also query /v1/models for the actual list.

流式响应需要特殊配置吗?Does streaming need special setup?

请求体设置 stream: true 即可。反向代理需要允许长连接并关闭响应缓冲;客户端应按 SSE 事件逐块读取。Set stream: true in the request. Reverse proxies must allow long-lived connections and disable response buffering. Clients should read SSE events incrementally.

遇到 429 应该怎么重试?How should I retry a 429?

使用带随机抖动的指数退避,并尊重响应中的重试提示。不要在高并发下立即循环重试,否则会放大限流。Use exponential backoff with jitter and honor any retry hint in the response. Do not retry in a tight loop under high concurrency.

排障时需要提供什么?What should I include in a support request?

提供请求时间、模型 ID、HTTP 状态、错误 code 和 request_id。不要发送完整 API Key 或包含敏感内容的请求体。Include the request time, model ID, HTTP status, error code, and request_id. Do not send the full API key or request bodies containing sensitive content.

下一步,发出第一条真实请求。Next: send the first real request.

创建密钥、复制模型 ID,然后回到你的客户端。遇到问题先看错误码,再带上 request_id 联系支持。Create a key, copy a model ID, and return to your client. If something fails, check the error code first and include the request ID when contacting support.

进入控制台