# Create a message
URL: https://docs.munito.ai/api/createMessage

POST /messages

Generate a response with the Anthropic Messages API. The Anthropic SDK uses your Munito key through `X-API-Key`. Set its base URL to `https://api.munito.ai/inference`.

- Send the conversation in `messages` and the system prompt in `system`.
- Set `stream: true` for Anthropic SSE events. A complete stream ends with `message_stop`. An incomplete stream ends with an `error` event.
- Use `tools` and `tool_choice` for tool calls. Reasoning models can return `thinking` content blocks.
- Set `thinking` to turn reasoning on (`enabled` or `adaptive`) or off (`disabled`). The API validates `budget_tokens` but does not enforce it. `max_tokens` bounds the whole answer.
- The API accepts `cache_control`, `service_tier` and `speed: "standard"`, and they change nothing: it caches each prompt prefix, and the `munito-service-tier` header selects the tier. `speed: "fast"` is not available.

The API requires `max_tokens`. Values above the model's output maximum use that maximum. A response that reaches the cap returns `stop_reason: "max_tokens"`.

Requests are stateless and billed per token. Use `/messages/count_tokens` to count input tokens without inference.

```json
{
  "operationId": "createMessage",
  "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
      }
    }
  ],
  "summary": "Create a message",
  "tags": [
    "Messages"
  ],
  "description": "Generate a response with the Anthropic Messages API. The Anthropic SDK uses your Munito key through `X-API-Key`. Set its base URL to `https://api.munito.ai/inference`.\n\n- Send the conversation in `messages` and the system prompt in `system`.\n- Set `stream: true` for Anthropic SSE events. A complete stream ends with `message_stop`. An incomplete stream ends with an `error` event.\n- Use `tools` and `tool_choice` for tool calls. Reasoning models can return `thinking` content blocks.\n- Set `thinking` to turn reasoning on (`enabled` or `adaptive`) or off (`disabled`). The API validates `budget_tokens` but does not enforce it. `max_tokens` bounds the whole answer.\n- The API accepts `cache_control`, `service_tier` and `speed: \"standard\"`, and they change nothing: it caches each prompt prefix, and the `munito-service-tier` header selects the tier. `speed: \"fast\"` is not available.\n\nThe API requires `max_tokens`. Values above the model's output maximum use that maximum. A response that reaches the cap returns `stop_reason: \"max_tokens\"`.\n\nRequests are stateless and billed per token. Use `/messages/count_tokens` to count input tokens without inference.",
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "required": [
            "model",
            "messages",
            "max_tokens"
          ],
          "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": "The conversation as Anthropic-style messages: `content` is a string or an array of content blocks.",
              "items": {
                "type": "object",
                "properties": {
                  "role": {
                    "type": "string",
                    "enum": [
                      "user",
                      "assistant"
                    ]
                  },
                  "content": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "array",
                        "items": {
                          "type": "object"
                        },
                        "description": "Content blocks: `text`, `image`, `tool_use`, `tool_result` and `thinking`."
                      }
                    ]
                  }
                }
              }
            },
            "max_tokens": {
              "type": "integer",
              "description": "Maximum tokens to generate. Required. Clamped to the model's output maximum."
            },
            "system": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "array",
                  "items": {
                    "type": "object"
                  },
                  "description": "`text` blocks."
                }
              ],
              "description": "System prompt (top-level, Anthropic-style): a string or an array of `text` blocks."
            },
            "stream": {
              "type": "boolean",
              "description": "Stream Anthropic SSE events (message_start … message_stop).",
              "default": false
            },
            "tools": {
              "type": "array",
              "description": "Anthropic-style tools the model may call (steer with `tool_choice`).",
              "items": {
                "type": "object"
              }
            }
          }
        },
        "example": {
          "model": "qwen/qwen3.8-27b",
          "max_tokens": 512,
          "messages": [
            {
              "role": "user",
              "content": "Explain intelligence sovereignty in one sentence."
            }
          ]
        }
      }
    }
  },
  "responses": {
    "200": {
      "description": "An Anthropic-compatible message.",
      "headers": {
        "request-id": {
          "description": "The id that Munito makes for each request, on the Messages routes. Quote it to support. Anthropic 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"
          }
        },
        "anthropic-ratelimit-requests-limit": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "anthropic-ratelimit-requests-remaining": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "anthropic-ratelimit-requests-reset": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "anthropic-ratelimit-tokens-limit": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "anthropic-ratelimit-tokens-remaining": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "anthropic-ratelimit-tokens-reset": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "anthropic-ratelimit-input-tokens-limit": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "anthropic-ratelimit-input-tokens-remaining": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "anthropic-ratelimit-input-tokens-reset": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "anthropic-ratelimit-output-tokens-limit": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "anthropic-ratelimit-output-tokens-remaining": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "anthropic-ratelimit-output-tokens-reset": {
          "description": "",
          "schema": {
            "type": "string"
          }
        }
      },
      "content": {
        "application/json": {
          "example": {
            "id": "msg_7f3c1a",
            "type": "message",
            "role": "assistant",
            "model": "qwen/qwen3.8-27b",
            "content": [
              {
                "type": "text",
                "text": "Intelligence sovereignty is the ability to run, govern, and improve your own AI on infrastructure you control, with no foreign cloud in the loop."
              }
            ],
            "stop_reason": "end_turn",
            "usage": {
              "input_tokens": 18,
              "output_tokens": 34
            }
          }
        }
      }
    }
  }
}
```

# 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."
    }
  }
}