Chat models
Build conversational applications with OpenAI- and Anthropic-compatible endpoints. Send text or image input, stream responses, and let the model call your tools.
Create an API key before calling the chat model endpoint.
Quickstart
Use https://open.wecoding.ai/v1 as the OpenAI-compatible base URL. Authenticate every request with a Bearer API key.
/v1/chat/completionscurl --request POST \
--url https://open.wecoding.ai/v1/chat/completions \
--header 'Authorization: Bearer $WECODING_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"model": "glm-5.2",
"messages": [
{ "role": "system", "content": "You are a concise assistant." },
{ "role": "user", "content": "Explain vector databases in one paragraph." }
]
}'{
"id": "chatcmpl_01K4...",
"request_id": "req_01K4...",
"created": 1788451200,
"model": "glm-5.2",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "A vector database stores and searches embeddings..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 28,
"completion_tokens": 34,
"total_tokens": 62
}
}Existing OpenAI SDK integrations can usually switch by changing only the base URL, API key, and model name.
Anthropic Messages API
Use the Anthropic-compatible endpoint with x-api-key or Bearer authentication. The Anthropic SDK can use the same WeCoding API key and glm-5.2 model.
/v1/messagescurl --request POST \
--url https://open.wecoding.ai/v1/messages \
--header 'x-api-key: $WECODING_API_KEY' \
--header 'anthropic-version: 2023-06-01' \
--header 'Content-Type: application/json' \
--data '{
"model": "glm-5.2",
"max_tokens": 1024,
"messages": [
{ "role": "user", "content": "Explain vector databases in one paragraph." }
]
}'OpenAI request parameters
| Field | Type | Description |
|---|---|---|
messages Required | array | Conversation messages. At least one message is required. |
model | string | Model identifier. Defaults to glm-5.2. |
stream | boolean | Return server-sent events when true. Defaults to false. |
temperature | number | Sampling temperature from 0 through 1. |
top_p | number | Nucleus sampling value from 0.01 through 1. |
max_tokens | integer | Maximum output tokens from 1 through 131,072. |
reasoning_effort | string | Reasoning level: max, xhigh, high, medium, low, minimal, or none. |
thinking | object | Model thinking configuration in OpenAI-compatible form. |
response_format | object | Controls structured response formatting. |
tools | array | Functions the model may choose to call. |
tool_choice | string | object | Controls whether and which tool the model calls. |
request_id | string | Optional client request identifier for tracing. |
user_id | string | Optional end-user identifier. |
Anthropic request differences
| Field | Type | Description |
|---|---|---|
max_tokens Required | integer | Required by the Anthropic Messages API. |
system | string | array | Top-level system instructions instead of a system message. |
messages Required | array | User and assistant messages in Anthropic format. |
anthropic-version | header | Accepted for Anthropic SDK compatibility. |
x-api-key Required | header | WeCoding API key. Authorization: Bearer is also accepted. |
Message roles
| Field | Type | Description |
|---|---|---|
system | role | Instructions that shape assistant behavior. |
user | role | Text or multimodal input from the user. |
assistant | role | A previous assistant response included for conversation history. |
tool | role | The result of a tool call, linked with tool_call_id. |
Stream a response
Set stream to true to receive OpenAI-compatible server-sent events. Process each data event in order and stop when the stream emits [DONE].
curl --no-buffer --request POST \
--url https://open.wecoding.ai/v1/chat/completions \
--header 'Authorization: Bearer $WECODING_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"model": "glm-5.2",
"messages": [{ "role": "user", "content": "Write a haiku about code." }],
"stream": true,
"stream_options": { "include_usage": true }
}'data: {"id":"chatcmpl_01K4...","choices":[{"delta":{"content":"Silent"}}]}
data: {"id":"chatcmpl_01K4...","choices":[{"delta":{"content":" loops awaken"}}]}
data: [DONE]Usage is finalized after the stream completes. If the client disconnects early, the platform still records the completed upstream usage when available.
Vision input
Pass an array of typed content items in a user message to combine text with an image URL.
{
"model": "glm-5.2",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "What is shown in this image?" },
{
"type": "image_url",
"image_url": { "url": "https://example.com/image.jpg" }
}
]
}
]
}Tool calling
Describe callable functions in tools. When the assistant returns tool_calls, run the requested function and append its result as a tool message before continuing the conversation.
{
"model": "glm-5.2",
"messages": [
{ "role": "user", "content": "What is the weather in Singapore?" }
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city",
"parameters": {
"type": "object",
"properties": { "city": { "type": "string" } },
"required": ["city"]
}
}
}
],
"tool_choice": "auto"
}Errors
Errors use the OpenAI-compatible error envelope. Keep request IDs from response headers or bodies when contacting support.
| Field | Type | Description |
|---|---|---|
400 | Bad request | Invalid request fields or unsupported input. |
401 | Unauthorized | The API key is missing, invalid, expired, or revoked. |