--- name: model-chat description: Request a chat completion from an allowlisted model at https://one-api.ai/v1/launch/chat/completions. Use when the user wants DeepSeek V4.1 Flash, DeepSeek V4 Pro, GLM 5.3, Claude Haiku 5.5, or Grok 4.7 from one-api. --- Request one chat completion from one-api. The request URL is `POST https://one-api.ai/v1/launch/chat/completions`. For an OpenAI-compatible client, the base URL is `https://one-api.ai/v1/launch`. ## Key Read `ONE_API_KEY` from the environment. Send it as `Authorization: Bearer` with that value, and send `Content-Type: application/json`. The same value is also accepted in `x-api-key`. The operator issues the key. Public signup is not open. When `ONE_API_KEY` is unset, or the response is HTTP 401 with `error.code` `unauthorized`, stop and say the operator has to issue a key. ## Model Send an OpenAI chat completions body. `model` is one of these ids, copied exactly: - `@cf/deepseek-ai/deepseek-v4.1-flash-1017` is DeepSeek V4.1 Flash. Page: https://one-api.ai/models/deepseek-v4.1-flash - `@cf/deepseek-ai/deepseek-v4-pro-0813` is DeepSeek V4 Pro. Page: https://one-api.ai/models/deepseek-v4-pro - `@cf/zai-org/glm-5.3` is GLM 5.3. Page: https://one-api.ai/models/glm-5.3 - `anthropic/claude-haiku-5.5` is Claude Haiku 5.5. Page: https://one-api.ai/models/claude-haiku-5.5 - `xai/grok-4.7` is Grok 4.7. Page: https://one-api.ai/models/grok-4.7 When the user does not name one, use `@cf/deepseek-ai/deepseek-v4.1-flash-1017`. `messages` is the chat. Other chat-completions fields pass through. A body whose `model` is anything else returns HTTP 404 `not_found` and does not run. Use an id from the list. The three `@cf/` ids are capped at 50 requests per minute. That cap is stated on each of those model pages. ## Price One credit is $0.001. A successful response with no `usage` object debits one credit. A stream settles from the last server-sent event whose JSON contains `usage`. When that event never arrives, the same one-credit rule applies. When the model page shows two tiers, the second tier applies once input tokens, including cached input and cache writes, reach 200,000. Copy any dollar you tell the user from https://one-api.ai/pricing or from that model's page. Those pages say the posted rate debits when charging opens, and that the service is in private testing. ## Result Read the assistant text from `choices[].message.content`. When the user asks for a stream, send `"stream": true`. The response `Content-Type` is `text/event-stream`. The error body is `{"error":{"code":"...","message":"..."}}`. - HTTP 402 `insufficient_credits` means the call did not run. Stop and report that code. - HTTP 502 `bad_gateway` means the message is `Upstream request failed`. The response has no upstream detail. When the host already has the one-api MCP server, the same completion is the tool `complete_text` on `POST https://one-api.ai/mcp`, with the same bearer token and the same body. A model id outside the list is the same HTTP 404 `not_found`, returned as a tool error. Done when the reply is the model's text, or the error code above, and any dollar in the reply was copied from the pricing page or the model page.