Private beta access is limited. Join the waitlist to receive an invitation.

Guides / Chat models

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.

Model · glm-5.2OpenAI compatibleAnthropic compatibleStreaming supportedBearer authentication
API key required

Create an API key before calling the chat model endpoint.

Create API Key

Quickstart

Use https://open.wecoding.ai/v1 as the OpenAI-compatible base URL. Authenticate every request with a Bearer API key.

POST/v1/chat/completions
Basic request
curl --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." }
    ]
  }'
Response
{
  "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.

POST/v1/messages
Anthropic request
curl --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

FieldTypeDescription
messages RequiredarrayConversation messages. At least one message is required.
modelstringModel identifier. Defaults to glm-5.2.
streambooleanReturn server-sent events when true. Defaults to false.
temperaturenumberSampling temperature from 0 through 1.
top_pnumberNucleus sampling value from 0.01 through 1.
max_tokensintegerMaximum output tokens from 1 through 131,072.
reasoning_effortstringReasoning level: max, xhigh, high, medium, low, minimal, or none.
thinkingobjectModel thinking configuration in OpenAI-compatible form.
response_formatobjectControls structured response formatting.
toolsarrayFunctions the model may choose to call.
tool_choicestring | objectControls whether and which tool the model calls.
request_idstringOptional client request identifier for tracing.
user_idstringOptional end-user identifier.

Anthropic request differences

FieldTypeDescription
max_tokens RequiredintegerRequired by the Anthropic Messages API.
systemstring | arrayTop-level system instructions instead of a system message.
messages RequiredarrayUser and assistant messages in Anthropic format.
anthropic-versionheaderAccepted for Anthropic SDK compatibility.
x-api-key RequiredheaderWeCoding API key. Authorization: Bearer is also accepted.

Message roles

FieldTypeDescription
systemroleInstructions that shape assistant behavior.
userroleText or multimodal input from the user.
assistantroleA previous assistant response included for conversation history.
toolroleThe 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].

Streaming request
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 }
  }'
text/event-stream
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.

Vision request body
{
  "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.

Tool request body
{
  "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.

FieldTypeDescription
400Bad requestInvalid request fields or unsupported input.
401UnauthorizedThe API key is missing, invalid, expired, or revoked.