Messages API (Chat Completions)
The /v1/chat/completions endpoint is the primary way to interact with Mira models. It is fully compatible with the OpenAI Chat Completions API format, making it easy to migrate existing applications.
Base URL and authentication
Endpoint
POST https://api.vmira.ai/v1/chat/completions
All requests require an API key in the Authorization header:
Header
Authorization: Bearer sk-mira-YOUR_API_KEY
Request structure
The request body is a JSON object with the following parameters:
modelstringRequiredModel ID: mira, mira-pro, mira-maxmessagesarrayRequiredArray of messages with role and content fieldsmax_tokensintegerOptionalMaximum number of tokens in the responsetemperaturenumberOptionalSampling temperature (0–2, default 1)top_pnumberOptionalNucleus sampling (0–1, default 1)streambooleanOptionalEnable streaming (default false)stopstring|arrayOptionalSequences where the model will stop generatingresponse_formatobjectOptionalResponse format, e.g. { type: "json_object" }Message format
Each message in the messages array contains a role and content. Supported roles:
- system — System prompt that sets model behavior. Usually the first message.
- user — Message from the user — a question, task, or request.
- assistant — Model response. Used for context in multi-turn conversations.
Example: basic request
cURL
cURL
curl https://api.vmira.ai/v1/chat/completions \
-H "Authorization: Bearer sk-mira-YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "mira",
"max_tokens": 1024,
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is machine learning?"
}
]
}'Python
Python
import requests
response = requests.post(
"https://api.vmira.ai/v1/chat/completions",
headers={
"Authorization": "Bearer sk-mira-YOUR_API_KEY",
"Content-Type": "application/json",
},
json={
"model": "mira",
"max_tokens": 1024,
"temperature": 0.7,
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain recursion in simple terms."},
],
},
)
data = response.json()
print(data["choices"][0]["message"]["content"])JavaScript
JavaScript (Node.js)
const response = await fetch("https://api.vmira.ai/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": "Bearer sk-mira-YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "mira",
max_tokens: 1024,
temperature: 0.7,
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What is an API?" },
],
}),
});
const data = await response.json();
console.log(data.choices[0].message.content);Response structure
The API returns a JSON object with the following structure:
JSON Response
{
"id": "chatcmpl-abc123def456",
"object": "chat.completion",
"created": 1711000000,
"model": "mira",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Machine learning is..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 150,
"total_tokens": 175
}
}Multi-turn conversations
To maintain conversation context, pass the full message history in the messages array. The model uses previous messages to understand context.
Multi-turn conversation
{
"model": "mira",
"messages": [
{ "role": "system", "content": "You are a programming assistant." },
{ "role": "user", "content": "Write a bubble sort function in Python." },
{ "role": "assistant", "content": "def bubble_sort(arr):\n n = len(arr)\n for i in range(n):\n for j in range(0, n-i-1):\n if arr[j] > arr[j+1]:\n arr[j], arr[j+1] = arr[j+1], arr[j]\n return arr" },
{ "role": "user", "content": "Now optimize it to stop early if the array is already sorted." }
]
}The more messages in the history, the more tokens are used. Trim older messages if you are approaching the model's context limit.
OpenAI SDK compatibility
Since the Mira API is compatible with the OpenAI format, you can use the official OpenAI SDK by simply pointing to our base URL:
Python (OpenAI SDK)
from openai import OpenAI
client = OpenAI(
api_key="sk-mira-YOUR_API_KEY",
base_url="https://api.vmira.ai/v1",
)
response = client.chat.completions.create(
model="mira",
max_tokens=1024,
messages=[
{"role": "user", "content": "Hello, Mira!"},
],
)
print(response.choices[0].message.content)JavaScript (OpenAI SDK)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "sk-mira-YOUR_API_KEY",
baseURL: "https://api.vmira.ai/v1",
});
const response = await client.chat.completions.create({
model: "mira",
max_tokens: 1024,
messages: [
{ role: "user", content: "Hello, Mira!" },
],
});
console.log(response.choices[0].message.content);All Mira API keys start with sk-mira-. Get your key at platform.vmira.ai.