Skip to main content
Send an ordered messages array to the Chat Completions endpoint and read the reply from choices[0].message.content. Use a model API key with access to the model you select.

Make a request

Create a key in Token management and set it as the LAOZHANG_API_KEY environment variable. The examples use gpt-5.4-mini; check model access for your token group in Models and pricing. Requests use Authorization: Bearer authentication and a JSON body containing model and messages.
The reply to this prompt should be connected. Replace the prompt with your application’s message once the client is configured.

Request fields

Start with model and messages. Optional fields and accepted values depend on the model; a request rejected for an unsupported parameter needs a field change before you retry it. See the official Chat Completions reference for upstream field definitions.

Messages and conversation history

Each message has a role and content. Use user for user input and assistant for previous model replies. Send the history your application needs with each request:
Instruction roles such as system or developer, tool messages, and multimodal content depend on the selected model. A text content string is sufficient for the basic request above.

Read the response

A text response contains a choices array. This shortened example shows the fields to read:
Read message.content for the answer and finish_reason to see why generation ended. A length finish reason means the reply reached an output or context limit; shorten the input or adjust the model’s supported output limit if you need a complete answer. For a model that supports tool calls, the reply may contain message.tool_calls instead of ordinary text. Preserve those calls and their matching results when continuing the conversation. Token counts may appear in usage; use call logs to review account charges.

Handle errors

For a client timeout, check whether the request appears in call logs before sending it again. The Python example disables automatic retries; add retry handling deliberately in your application. When contacting support, include the request time, endpoint, model, token group, and error message with credentials removed. Never send your API key.