Skip to main content

Overview

The Chat Completions API provides an OpenAI-compatible interface for conversational AI with Qwen models. It supports chat conversations, function calling, streaming responses, and custom generation parameters.

Endpoint

Request

Request Body

Parameters

string
required
Model identifier (currently returns “gpt-3.5-turbo” regardless of input)
array
required
Array of message objects forming the conversation. Each message has:
  • role: One of "system", "user", "assistant", or "function"
  • content: Message text content
  • function_call: (Optional) Function call object for assistant messages
float
default:"None"
Sampling temperature between 0 and 2:
  • < 0.01: Effectively greedy decoding (sets top_k=1)
  • 0.7-0.9: Balanced creativity
  • > 1.0: More random
Note: Tuning top_p is recommended over temperature.
float
default:"None"
Nucleus sampling probability threshold (0-1)
int
default:"None"
Limits sampling to top K tokens
int
default:"None"
Maximum total sequence length (input + output tokens)
boolean
default:"false"
Whether to stream partial responses as Server-Sent Events (SSE)
array[string]
default:"None"
Up to 4 sequences where generation should stop:
array
default:"None"
List of function definitions for function calling:
Note: Not supported in stream mode.

Response

Non-Streaming Response

Response Fields

string
Model identifier from request
string
Object type: "chat.completion" or "chat.completion.chunk" (streaming)
integer
Unix timestamp of when the completion was created
array
Array of completion choices (usually length 1)
integer
Choice index (always 0)
object
Generated message with:
  • role: Always "assistant"
  • content: Generated text
  • function_call: (Optional) Function call object
string
Reason generation stopped:
  • "stop": Natural completion or stop sequence
  • "length": Reached max_length
  • "function_call": Model wants to call a function

Streaming Responses

When stream=true, responses are sent as Server-Sent Events:

Stream Response Format

Each chunk is a JSON object:

Function Calling

The API supports function calling for tool use:

Function Call Response

Python Client Example

Multi-turn Conversation

Error Responses

Invalid Request

Status Codes

  • 200: Success
  • 400: Bad request (invalid parameters or message format)
  • 401: Unauthorized (if API authentication is enabled)
  • 500: Internal server error