Basic Usage
Getting started with the Responses API
The Responses API supports both simple string input and structured message arrays, making it easy to get started with basic text generation.
Simple String Input
The simplest way to use the API is with a string input:
const response = await fetch('https://llm.onerouter.pro/v1/responses', {
method: 'POST',
headers: {
'Authorization': 'Bearer <<API_KEY>>',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'o4-mini',
input: 'What is the meaning of life?',
max_output_tokens: 9000,
}),
});
const result = await response.json();
console.log(result);import requests
response = requests.post(
'https://llm.onerouter.pro/v1/responses',
headers={
'Authorization': 'Bearer <<API_KEY>>',
'Content-Type': 'application/json',
},
json={
'model': 'o4-mini',
'input': 'What is the meaning of life?',
'max_output_tokens': 9000,
}
)
result = response.json()
print(result)Structured Message Input
For more complex conversations, use the message array format:
Response Format
The API returns a structured response with the generated content:
Streaming Responses
Enable streaming for real-time response generation:
Common Parameters
model
string
Required. Model to use (e.g., o4-mini)
input
string or array
Required. Text or message array
stream
boolean
Enable streaming responses (default: false)
max_output_tokens
integer
Maximum tokens to generate
temperature
number
Sampling temperature (0-2)
top_p
number
Nucleus sampling parameter (0-1)
Error Handling
Handle common errors gracefully:
Multiple Turn Conversations
Since the Responses API is stateless, you must include the full conversation history in each request to maintain context:
The `id` and `status` fields are required for any `assistant` role messages included in the conversation history. Always include the complete conversation history in each request. The API does not store previous messages, so context must be maintained client-side.
Next Steps
Learn about Reasoning capabilities
Explore Tool Calling functionality
Last updated