Chat Completions API
Minimal request, common fields, reading responses, and multi-turn conversation usage for POST /v1/chat/completions.
Start with this endpoint when using an OpenAI-compatible client, or when you already have chat.completions.create code. The full address is https://1zheai.com/v1/chat/completions; for SDKs, fill in the Base URL only up to /v1.
Minimal Request
Section titled “Minimal Request”First set ONEZHE_API_KEY in your terminal to this site’s API key. The model below must exist in your available model list .
curl --fail-with-body --connect-timeout 10 --max-time 120 \ https://1zheai.com/v1/chat/completions \ -H "Authorization: Bearer $ONEZHE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-5.6-sol", "messages": [{"role": "user", "content": "请用一句中文解释 DNS 的作用。"}] }'--fail-with-body makes HTTP errors return a non-zero exit code while preserving the error body; requires curl 7.76 or later. On older versions, use -i first to view the status code.
Common Fields
Section titled “Common Fields”| Field | Type | Usage |
|---|---|---|
model | string | Required. Copy this site’s model ID; do not add vendor prefixes from other platforms. |
messages | array | Required. Send this round’s question and the history messages to retain, in order. |
messages[].role | string | For normal conversation use user / assistant; support for the system instruction role depends on the model. |
messages[].content | string or content block array | Use a string for plain text first; image input requires the model to support the corresponding content block. |
stream | boolean | When set to true, read SSE instead of treating the entire response as a single JSON. |
temperature | number | Optional; some reasoning models do not support modifying it. Omit it first, then verify item by item. |
tools / tool_choice | array / string or object | Optional; both the model and upstream must support them. Actual tool execution is performed by your program. |
Output limit parameters vary by model. Do not mechanically swap Claude’s max_tokens, Responses’ max_output_tokens, and Chat Completions parameters; refer to the selected model’s requirements, and on a 400 error check the error body first.
How to Read the Response
Section titled “How to Read the Response”The plain text result is located at choices[0].message.content. The finish reason is at choices[0].finish_reason; when tool calls are returned, the text may be empty and you need to read message.tool_calls. The response’s id, model, and usage can be used to verify this call.
Below only shows the structure you need to pay attention to; omitted fields and numbers do not represent actual request results:
{ "id": "example-completion", "object": "chat.completion", "model": "gpt-5.6-sol", "choices": [{ "index": 0, "message": {"role": "assistant", "content": "DNS 将域名解析为网络地址。"}, "finish_reason": "stop" }]}Multi-Turn Conversation
Section titled “Multi-Turn Conversation”The endpoint does not automatically remember the previous round just because you reuse the same API key. Send the history you want to retain together:
{ "model": "gpt-5.6-sol", "messages": [ {"role": "user", "content": "我正在学习 DNS。"}, {"role": "assistant", "content": "我们可以从域名解析开始。"}, {"role": "user", "content": "它和 HTTP 有什么区别?"} ]}The longer the history, the larger the request. Applications should trim or summarize according to context limits, and keep complete tool call and result pairs.
Streaming and Next Steps
Section titled “Streaming and Next Steps”After adding "stream": true, text deltas come from choices[].delta.content. Some events have no text or choices is empty, so you must check when reading; see Streaming Output for details.
Run the Python / Node.js full example directly, or switch to Responses ; for Claude native parameters see Messages .
