Chat completions

The chat completions endpoint is the primary way to interact with Mira models. It accepts a list of messages (a conversation) and returns a model-generated response. The API is fully compatible with the OpenAI format.

Endpoint

POST/v1/chat/completionsCreate a chat completion

Request parameters

modelstringRequiredModel ID: mira, mira-pro, or mira-max
messagesarrayRequiredArray of conversation messages (max 200). Each message has a role and content.
temperaturefloatOptionalRandomness (0-2). Lower values make responses more deterministic. Default 0.7.
max_tokensintegerOptionalMaximum number of tokens in the response. Default 4096, max 16384.
streambooleanOptionalEnable streaming via Server-Sent Events. Default false.
Each message is limited to 32,000 characters. Additional OpenAI API parameters (top_p, stop, tools, response_format, etc.) are planned for future releases.

Message format

Each message in the messages array contains two required fields:

rolestringRequiredThe author's role: "system", "user", or "assistant"
contentstringRequiredThe text content of the message
  • systemThe system message sets the model's behavior. Typically placed first in the array.
  • userUser messages are the input the model should respond to.
  • assistantPrevious model responses. Used to continue a conversation.

Full request example

cURL

cURL
curl https://api.vmira.ai/v1/chat/completions \
  -H "Authorization: Bearer $MIRA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mira",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Explain recursion in simple terms"}
    ],
    "max_tokens": 1024,
    "temperature": 0.7
  }'

Python

Python
import os
import requests

response = requests.post(
    "https://api.vmira.ai/v1/chat/completions",
    headers={
        "Authorization": f"Bearer {os.environ['MIRA_API_KEY']}",
        "Content-Type": "application/json",
    },
    json={
        "model": "mira",
        "messages": [
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "Explain recursion in simple terms"},
        ],
        "max_tokens": 1024,
        "temperature": 0.7,
    },
)

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 ${process.env.MIRA_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "mira",
    messages: [
      { role: "system", content: "You are a helpful assistant." },
      { role: "user", content: "Explain recursion in simple terms" },
    ],
    max_tokens: 1024,
    temperature: 0.7,
  }),
});

const data = await response.json();
console.log(data.choices[0].message.content);

Response format

JSON
{
  "id": "chatcmpl-abc123def456",
  "object": "chat.completion",
  "created": 1711000000,
  "model": "mira",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Recursion is when a function calls itself..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 150,
    "total_tokens": 175
  }
}

Response fields

idstringRequiredUnique completion identifier
objectstringRequiredObject type, always "chat.completion"
createdintegerRequiredUnix timestamp of creation
modelstringRequiredThe model used for the completion
choicesarrayRequiredArray of response choices (usually 1 unless n is specified)
usageobjectRequiredToken usage info (prompt_tokens, completion_tokens, total_tokens)

Streaming

When stream: true, the response arrives in chunks via Server-Sent Events (SSE). Each chunk contains a delta with new content. The stream ends with a [DONE] message.

Streaming response format
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1711000000,"model":"mira","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1711000000,"model":"mira","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1711000000,"model":"mira","choices":[{"index":0,"delta":{"content":" world"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1711000000,"model":"mira","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

Streaming in Python

Python
import os
import requests

response = requests.post(
    "https://api.vmira.ai/v1/chat/completions",
    headers={
        "Authorization": f"Bearer {os.environ['MIRA_API_KEY']}",
        "Content-Type": "application/json",
    },
    json={
        "model": "mira",
        "messages": [{"role": "user", "content": "Hello"}],
        "stream": True,
    },
    stream=True,
)

for line in response.iter_lines():
    if line:
        text = line.decode("utf-8")
        if text.startswith("data: ") and text != "data: [DONE]":
            import json
            chunk = json.loads(text[6:])
            delta = chunk["choices"][0]["delta"]
            if "content" in delta:
                print(delta["content"], end="", flush=True)

Streaming in JavaScript

JavaScript (Node.js)
const response = await fetch("https://api.vmira.ai/v1/chat/completions", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.MIRA_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "mira",
    messages: [{ role: "user", content: "Hello" }],
    stream: true,
  }),
});

const reader = response.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;

  const text = decoder.decode(value);
  for (const line of text.split("\n")) {
    if (line.startsWith("data: ") && line !== "data: [DONE]") {
      const chunk = JSON.parse(line.slice(6));
      const content = chunk.choices[0]?.delta?.content;
      if (content) process.stdout.write(content);
    }
  }
}
Additional parameters (tools, tool_choice, response_format) are planned for future API updates. To get JSON responses, include instructions in the system prompt.

Next steps