Chat Completion
Generate chat completions with various AI models
Endpoint
POST https://api.firstrouter.ai/v1/chat/completions
Headers
Bearer token for authentication. Format: Bearer YOUR_API_KEY
Request
This endpoint expects an object.
The model ID to use. e.g. openai/gpt-4o-mini
Array of message objects representing the conversation history.
Show 2 properties
The role of the message author (system, user, assistant)
The content of the message
Controls randomness in the output. Range: 0.0 to 2.0. Higher values make output more random.
Maximum number of tokens to generate in the completion.
Whether to stream back partial progress as data-only server-sent events.
Nucleus sampling parameter. Range: 0.0 to 1.0. Controls diversity via nucleus sampling.
How many chat completion choices to generate for each input message.
Up to 4 sequences where the API will stop generating further tokens.
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. See more information about frequency and presence penalties.
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text, decreasing the model's likelihood to repeat the same line verbatim. See more information about frequency and presence penalties.
Modify the likelihood of specified tokens appearing in the completion. Accepts a json object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.
A unique identifier representing your end-user, which can help OpenAI monitor and detect abuse. Learn more.
Request Example
curl -X POST "https://api.firstrouter.ai/v1/chat/completions" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello, how are you?"
}
],
"model": "openai/gpt-4o-mini",
"temperature": 0.7,
"max_tokens": 150
}'
Response Example
{
"id": "chatcmpl-ba101e0655344b54bd5b64be46a6624c",
"model": "gemini-2.5-flash-preview-05-20",
"object": "chat.completion",
"created": 1750777563,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "✋ High five! Right back at ya!",
"reasoning_content": "That covers the visual with the emoji, and answers appropriately."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 6,
"completion_tokens": 445,
"total_tokens": 451,
"prompt_tokens_details": {
"cached_tokens": 0,
"text_tokens": 6,
"audio_tokens": 0,
"image_tokens": 0
},
"completion_tokens_details": {
"text_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 436
},
"input_tokens": 0,
"output_tokens": 0,
"input_tokens_details": null
}
}