GPT-5.1 - Complete API Reference
- Use OpenAI SDK format to call GPT-5.1 series models
- Synchronous processing mode, real-time response
- Available models: gpt-5.1 (base), gpt-5.1-chat (optimized for conversation), gpt-5.1-thinking (with reasoning output)
- Text conversation: Single or multi-turn contextual dialogue
- System prompts: Customize AI role and behavior
- Multimodal input: Supports text + image mixed input
- Tool calling: Supports Function Calling
- Reasoning output: gpt-5.1-thinking returns reasoning_content field showing thought process
Authorization
All APIs require Bearer Token authentication **Get API Key:** Visit [API Key Management Page](https://starmagic.ai/app/api-keys) to get your API Key **Add to request header:** ``` Authorization: Bearer YOUR_API_KEY ```
Authorization: Bearer YOUR_API_KEYRequest body
application/jsonModel name for chat completion - **gpt-5.1**: Base model for general tasks - **gpt-5.1-chat**: Optimized for conversational tasks - **gpt-5.1-thinking**: Features reasoning capabilities with thinking process output (returns reasoning_content)
"gpt-5.1"List of messages for the conversation, supports multi-turn dialogue and multimodal input
[
{
"role": "user",
"content": null
}
]Whether to stream the response - `true`: Stream response, returns content chunk by chunk in real-time - `false`: Wait for complete response and return all at once
falseMaximum number of tokens to generate in the response
2000Sampling temperature, controls randomness of output - Lower values (e.g., 0.2): More deterministic and focused output - Higher values (e.g., 1.5): More random and creative output
1Nucleus sampling parameter - Controls sampling from tokens with cumulative probability - For example, 0.9 means sampling from tokens with top 90% cumulative probability
0.9Frequency penalty, number between -2.0 and 2.0 - Positive values penalize new tokens based on their frequency in the text
0Presence penalty, number between -2.0 and 2.0 - Positive values penalize new tokens based on whether they appear in the text
0Stop sequences, generation stops when these sequences are matched
List of tools for Function Calling
[
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a given location",
"parameters": {}
}
}
]Response
application/jsonResponse body
Unique identifier for the chat completion
"chatcmpl-abc123"The model used for completion
"gpt-5.1"Response type
"chat.completion"Unix timestamp when the completion was created
1698999496List of completion choices
[
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hi there! How can I help you?",
"reasoning_content": "Let me think about this step by step..."
},
"finish_reason": "stop"
}
]Token usage statistics
{
"prompt_tokens": 8,
"completion_tokens": 292,
"total_tokens": 300
}
