# Chat completion
URL: https://docs.munito.ai/api/createChatCompletion

POST /chat/completions

Create a chat completion with an open model. Set the OpenAI SDK base URL to https://api.munito.ai/inference/v1 and use your Munito API key. Both Authorization: Bearer and X-API-Key are accepted. Use stream for streamed output, tools for function calls, and response_format for structured output. Each model accepts its own parameters, media types, and limits, and the API answers 400 to a request outside them. Images and video can use inline data or validated remote URLs. Audio uses inline data only. Set store to true to retain the completion. Account limits can further restrict output.

```json
{
  "operationId": "createChatCompletion",
  "summary": "Chat completion",
  "tags": [
    "Completions"
  ],
  "parameters": [
    {
      "name": "munito-service-tier",
      "in": "header",
      "description": "priority, standard or flex. The response names the tier that is billed; see x-ratelimit-over-limit. See [Service tiers](https://docs.munito.ai/service-tiers).",
      "schema": {
        "type": "string",
        "enum": [
          "priority",
          "standard",
          "flex"
        ],
        "default": "standard"
      }
    },
    {
      "name": "munito-affinity",
      "in": "header",
      "description": "An opaque token. Send it back with the next request of the conversation, so that the prompt cache can serve it. Without it, the API uses `prompt_cache_key`, `x-session-affinity` or `user`, or `metadata.user_id` on the Messages API, for the same purpose.",
      "schema": {
        "type": "string"
      }
    },
    {
      "name": "munito-overflow",
      "in": "header",
      "description": "off, model, class or any: what may serve a chat request that its own capacity refuses. The response names the step that served it. Off by default. The request keeps its region, and you pay the price of the model that you asked for. Flex, background and free-tier requests do not overflow.",
      "schema": {
        "type": "string",
        "enum": [
          "off",
          "model",
          "class",
          "any"
        ],
        "default": "off"
      }
    },
    {
      "name": "munito-prompt-cache-isolation-key",
      "in": "header",
      "description": "A secret string of up to 256 characters. Requests with different keys never share the prompt cache. The body field prompt_cache_isolation_key does the same. See [Prompt caching](https://docs.munito.ai/features/prompt-caching#isolation).",
      "schema": {
        "type": "string",
        "maxLength": 256
      }
    },
    {
      "name": "prefer",
      "in": "header",
      "description": "`respond-async`: answer 202 at once. Then poll the `location` until the request finishes.",
      "schema": {
        "type": "string",
        "enum": [
          "respond-async"
        ]
      }
    }
  ],
  "description": "Create a chat completion with an open model. Set the OpenAI SDK base URL to https://api.munito.ai/inference/v1 and use your Munito API key. Both Authorization: Bearer and X-API-Key are accepted. Use stream for streamed output, tools for function calls, and response_format for structured output. Each model accepts its own parameters, media types, and limits, and the API answers 400 to a request outside them. Images and video can use inline data or validated remote URLs. Audio uses inline data only. Set store to true to retain the completion. Account limits can further restrict output.",
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "required": [
            "model",
            "messages"
          ],
          "properties": {
            "model": {
              "type": "string",
              "description": "Model id from GET /models, e.g. `qwen/qwen3.8-27b`.",
              "example": "qwen/qwen3.8-27b"
            },
            "messages": {
              "type": "array",
              "description": "OpenAI-style messages. Content can contain text and media parts when the selected model supports them: `image_url`, `video_url`, or `input_audio` for an audio model. An `input_audio` part holds base64 `data` and its `format` (`wav`, `mp3`, `flac`, `ogg`, `webm`, `m4a` or `mp4`), at most 30 seconds of audio, and up to 4 parts in one request. Send a longer recording to POST /audio/transcriptions.",
              "items": {
                "type": "object",
                "properties": {
                  "role": {
                    "type": "string",
                    "enum": [
                      "developer",
                      "system",
                      "user",
                      "assistant",
                      "tool"
                    ]
                  },
                  "content": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "array",
                        "items": {
                          "type": "object"
                        },
                        "description": "Content parts: `text`, `image_url`, `video_url`, `input_audio` or `file`."
                      }
                    ],
                    "nullable": true
                  }
                }
              }
            },
            "max_tokens": {
              "type": "integer",
              "description": "Maximum tokens to generate. Omit it to allow the output maximum of the model. A larger value uses that maximum."
            },
            "temperature": {
              "type": "number",
              "description": "Sampling temperature (0–2). Omit it to use the default of the model."
            },
            "stream": {
              "type": "boolean",
              "description": "Stream tokens back as server-sent events.",
              "default": false
            },
            "tools": {
              "type": "array",
              "description": "OpenAI-style function tools the model may call (steer with `tool_choice`).",
              "items": {
                "type": "object"
              }
            },
            "store": {
              "type": "boolean",
              "description": "Persist the completion for later retrieval via GET /chat/completions/{id}.",
              "default": false
            },
            "prompt_cache_isolation_key": {
              "type": "string",
              "maxLength": 256,
              "description": "A secret key. Requests with different keys never share the prompt cache. See [Prompt caching](https://docs.munito.ai/features/prompt-caching#isolation)."
            }
          }
        },
        "example": {
          "model": "qwen/qwen3.8-27b",
          "messages": [
            {
              "role": "user",
              "content": "Explain intelligence sovereignty in one sentence."
            }
          ],
          "max_tokens": 512
        }
      }
    }
  },
  "responses": {
    "200": {
      "description": "An OpenAI-compatible chat completion.",
      "headers": {
        "x-request-id": {
          "description": "The id that Munito makes for each request. Quote it to support. OpenAI sends the same header.",
          "schema": {
            "type": "string"
          }
        },
        "munito-region": {
          "description": "The jurisdiction that served the request.",
          "schema": {
            "type": "string"
          }
        },
        "munito-service-tier": {
          "description": "priority, standard or flex. The response names the tier that is billed; see x-ratelimit-over-limit.",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-over-limit": {
          "description": "yes when the request exceeded a rate limit and ran on spare capacity: a free seat of its own tier, or the flex band for background work and OCR. Fireworks sends the same header.",
          "schema": {
            "type": "string"
          }
        },
        "munito-affinity": {
          "description": "An opaque token. Send it back with the next request of the conversation, so that the prompt cache can serve it. Without it, the API uses `prompt_cache_key`, `x-session-affinity` or `user`, or `metadata.user_id` on the Messages API, for the same purpose.",
          "schema": {
            "type": "string"
          }
        },
        "munito-overflow": {
          "description": "off, model, class or any: what may serve a chat request that its own capacity refuses. The response names the step that served it.",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-limit-requests": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-remaining-requests": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-reset-requests": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-limit-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-remaining-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-reset-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-limit-input-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-remaining-input-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-reset-input-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-limit-output-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-remaining-output-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-reset-output-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        }
      },
      "content": {
        "application/json": {
          "example": {
            "id": "chatcmpl-7f3c1a",
            "object": "chat.completion",
            "model": "qwen/qwen3.8-27b",
            "choices": [
              {
                "index": 0,
                "message": {
                  "role": "assistant",
                  "content": "Intelligence sovereignty is the ability to run, govern, and improve your own AI on infrastructure you control, with no foreign cloud in the loop."
                },
                "finish_reason": "stop"
              }
            ],
            "usage": {
              "prompt_tokens": 18,
              "completion_tokens": 34,
              "total_tokens": 52
            }
          }
        }
      }
    },
    "202": {
      "description": "Accepted, when the request sends `Prefer: respond-async`. Poll the `location` until it finishes.",
      "headers": {
        "x-request-id": {
          "description": "The id that Munito makes for each request. Quote it to support. OpenAI sends the same header.",
          "schema": {
            "type": "string"
          }
        },
        "munito-region": {
          "description": "The jurisdiction that served the request.",
          "schema": {
            "type": "string"
          }
        },
        "munito-service-tier": {
          "description": "priority, standard or flex. The response names the tier that is billed; see x-ratelimit-over-limit.",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-over-limit": {
          "description": "yes when the request exceeded a rate limit and ran on spare capacity: a free seat of its own tier, or the flex band for background work and OCR. Fireworks sends the same header.",
          "schema": {
            "type": "string"
          }
        },
        "location": {
          "description": "Where the result or the redirect target is.",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-limit-requests": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-remaining-requests": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-reset-requests": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-limit-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-remaining-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-reset-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-limit-input-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-remaining-input-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-reset-input-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-limit-output-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-remaining-output-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-reset-output-tokens": {
          "description": "",
          "schema": {
            "type": "string"
          }
        }
      }
    }
  }
}
```

# Shared API schemas
{
  "securitySchemes": {
    "BearerAuth": {
      "type": "http",
      "scheme": "bearer",
      "description": "Your Munito API key."
    },
    "ApiKeyAuth": {
      "type": "apiKey",
      "in": "header",
      "name": "x-api-key",
      "description": "Your Munito API key."
    }
  }
}