> ## Documentation Index
> Fetch the complete documentation index at: https://docs.muna.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a Chat Completion

Creates a chat completion. Pass `stream: true` to stream the completion as server-sent events.

```py Python theme={null}
from openai import OpenAI
import os

# 💥 Create an OpenAI client, pointed at Muna
openai = OpenAI(
  api_key=os.environ["MUNA_API_KEY"],
  base_url="https://inference.muna.ai/v1"
)

# 🔥 Create a chat completion
completion = openai.chat.completions.create(
  model="@qwen/qwen-3.8-27b",
  messages=[{ "role": "user", "content": "What is the capital of France?" }]
)

# 🚀 Print the result
print(completion.choices[0].message)
```

```ts JavaScript theme={null}
import OpenAI from "openai"

// 💥 Create an OpenAI client, pointed at Muna
const openai = new OpenAI({
  apiKey: process.env.MUNA_API_KEY,
  baseURL: "https://inference.muna.ai/v1"
});

// 🔥 Create a chat completion
const completion = await openai.chat.completions.create({
  model: "@qwen/qwen-3.8-27b",
  messages: [{ role: "user", content: "What is the capital of France?" }]
});

// 🚀 Print the result
console.log(completion.choices[0]);
```

```py Python (streaming) theme={null}
# 🔥 Stream a chat completion
stream = openai.chat.completions.create(
  model="@qwen/qwen-3.8-27b",
  messages=[{ "role": "user", "content": "What is life?" }],
  stream=True
)

# 🚀 Use completion chunks
for chunk in stream:
  ...
```

```bash curl theme={null}
curl https://inference.muna.ai/v1/chat/completions \
  -H "Authorization: Bearer $MUNA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "@qwen/qwen-3.8-27b",
    "messages": [{ "role": "user", "content": "What is the capital of France?" }]
  }'
```

```json Response theme={null}
{
  "id": "chatcmpl-6f1c2b9e-4d3a-4b8e-9c1f-2a7d5e8b0c34",
  "object": "chat.completion",
  "created": 1791516000,
  "model": "@qwen/qwen-3.8-27b",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The capital of France is Paris."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 16,
    "completion_tokens": 8,
    "total_tokens": 24,
    "prompt_tokens_details": { "cached_tokens": 0 }
  }
}
```

### Body

**model** `string` *required*

Model tag.

**messages** `Message[]` *required*

Messages comprising the conversation so far.

**properties**

**role** `string` *required*

Message role: `system`, `user`, `assistant`, or `tool`.

**content** `string | ContentPart[]`

Message content. Content parts can be `text` or `image_url`, for models that accept images.

**tool\_calls** `ToolCall[]`

Tool calls made by the model, on `assistant` messages.

**tool\_call\_id** `string`

Tool call that this message responds to, on `tool` messages.

**stream** `boolean`

Whether to stream the completion as server-sent events. Defaults to `false`.

**tools** `Tool[]`

Function tools the model may call.

**tool\_choice** `string`

Tool choice mode: `auto` or `none`. Defaults to `auto`.

**reasoning\_effort** `string`

Reasoning effort for reasoning models: `none`, `minimal`, `low`, `medium`, `high`, or `xhigh`.

**max\_completion\_tokens** `integer`

Maximum number of tokens to generate. Also accepted as `max_tokens`.

**temperature** `number`

Sampling temperature.

**top\_p** `number`

Nucleus sampling coefficient.

**seed** `integer`

Sampling seed for reproducible outputs.

### Response

**id** `string` *required*

Chat completion identifier.

**object** `string` *required*

Object type, always `chat.completion`.

**created** `integer` *required*

Unix timestamp, in seconds, when the completion was created.

**model** `string` *required*

Model tag.

**choices** `Choice[]` *required*

Generated completion choices.

**properties**

**index** `integer` *required*

Choice index.

**message** `Message` *required*

Generated message.

**properties**

**role** `string` *required*

Message role, always `assistant`.

**content** `string`

Message content.

**reasoning\_content** `string`

Model reasoning, for reasoning models.

**tool\_calls** `ToolCall[]`

Tool calls made by the model.

**finish\_reason** `string`

Reason the model stopped generating: `stop`, `length`, or `tool_calls`.

**usage** `Usage`

Token usage.

**properties**

**prompt\_tokens** `integer` *required*

Number of tokens in the prompt.

**completion\_tokens** `integer` *required*

Number of tokens in the completion.

**total\_tokens** `integer` *required*

Total number of tokens.

**prompt\_tokens\_details.cached\_tokens** `integer`

Number of prompt tokens served from cache, billed at the cached input rate.

**completion\_tokens\_details.reasoning\_tokens** `integer`

Number of completion tokens spent on reasoning.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.