Text Generation
The Text Generation in Compass supports chat completions that take text input and generate text output. These inputs are accepted as a text message,a string, an array, or a message object. Each message has a role, either a user, system, or an assistant, and includes content. The user message provides requests or comments for the assistant to respond. Assistant messages store previous responses, but you can also write them to give examples of desired behavior. You can define instructions in the user messages, but the system messages are more effective. Only one system message per conversation can be set.
Text Inputs
Chat models take a list of messages as input and return a model-generated message as output. Although the chat format is designed to make multi-conversations easy, it is also useful for single-turn tasks without any conversation.
Sample Request Format
{
"model": "glm-5.2-signature-cloud",
"messages": [
{
"role": "user",
"content": "Hi"
}
],
"stream": false
}
Learn more about text generation through Chat Completions API reference documentation.
Sample Response Format
{
"id": "chatcmpl-b8d79c7d37789522c78b2fa343f29319",
"object": "chat.completion",
"created": 1791974357,
"model": "glm-5.2-signature-cloud",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hi there! I'm GLM, trained by Z.ai. How can I assist you today? Whether you have questions or just want to chat, I'm happy to help.",
"refusal": null,
"annotations": null,
"audio": null,
"function_call": null,
"tool_calls": [],
"reasoning": "Let me analyze this greeting and consider how to respond appropriately.\n\nLooking at this simple \"Hi\" greeting, I should consider several factors:\n- It's a basic social greeting\n- The user hasn't specified any particular topic or question\n- I should be welcoming but not overly verbose\n- I need to maintain a professional yet friendly tone\n- I should invite further conversation\n\nThe appropriate response should:\n1. Return the greeting\n2. Introduce myself briefly\n3. Offer assistance\n4. Keep it concise since the initial message was minimal\n\nI should avoid:\n- Being too lengthy or overwhelming\n- Making assumptions about what the user wants\n- Being overly formal or informal\n- Providing unnecessary information\n\nThis calls for a balanced response that's welcoming and opens the door for further conversation while respecting the brevity of the initial greeting."
},
"logprobs": null,
"finish_reason": "stop",
"stop_reason": 154827,
"token_ids": null,
"routed_experts": null
}
],
"service_tier": null,
"system_fingerprint": null,
"usage": {
"prompt_tokens": 13,
"total_tokens": 220,
"completion_tokens": 207,
"prompt_tokens_details": null
},
"prompt_logprobs": null,
"prompt_token_ids": null,
"prompt_text": null,
"kv_transfer_params": null
}
The reply can be extracted with message = completion.choices[0].message.content.
Each response includes finish_reason, and the possible values are:
stop: API returns a complete message or a message terminated by one of the stop sequences provided via the stop parameterlength: Incomplete model output due to max_tokens parameter or token limitfunction_call: The model decided to call a functioncontent_filter: Omitted content due to a flag from our content filtersnull: API response still in progress or incomplete
Based on the input parameters, the model response may include information other than the above parameters.