---
title: "Generate a message (Anthropic-compatible)"
method: POST
path: "/v1/messages"
tags: ["Messages"]
---

# Generate a message (Anthropic-compatible)

`POST /v1/messages`

## Request

- Base URL: `https://inference.openrelay.inc`
- URL: `https://inference.openrelay.inc/v1/messages`
- Auth: HTTP bearer

Generates a model response in the Anthropic Messages shape, a drop-in for the Anthropic SDKs and Claude Code on models that support messages.
Messages is a second online family alongside Chat Completions; check a model's supported_apis on GET /v1/models before calling it rather than assuming.

Requires a funded balance. Send the API key as x-api-key (the Anthropic SDK convention) or as Authorization Bearer; either is accepted. Set "stream" to true for event-typed Server-Sent Events (message_start, content_block_delta, message_stop, and so on). The request body is capped at 10 MiB.

Requires the `inference.invoke` permission. See [Permissions](https://docs.openrelay.inc/docs/permissions) for the roles and API key permissions that include it.

## Request body

- MessageRequest: An Anthropic-compatible Messages request. Opaque: unlisted Anthropic parameters (temperature, top_p, stop_sequences, tools, tool_choice, ...) are forwarded as sent.
  - `max_tokens` integer, required: Upper bound on tokens to generate. Required (unlike Chat Completions).
  - `messages` object[], required: The conversation so far: {role, content} objects (user, assistant only; use the top-level system field for a system prompt).
  - `model` string, required: An OpenRelay public model id, e.g. openrelay/glm-5.2.
  - `stream` boolean: Stream the response as event-typed Server-Sent Events.
  - `system` string: The system prompt, as a top-level field.

## Response `200`

OK

- MessageResponse: An Anthropic message object (opaque; additionalProperties carries the rest of the dialect).
  - `content` object[]
  - `id` string
  - `model` string: Always the public OpenRelay model id requested.
  - `openrelay` OpenRelayResponseMeta: What the request is billed, on every online inference response.
    - `cost_nano_usd` integer: What this call is billed, in nanoUSD. Also sent as the OpenRelay-Cost-Nano-USD header.
    - `priced_at` string: Pricing basis, e.g. online.
  - `role` 'assistant'
  - `stop_reason` string
  - `type` 'message'
  - `usage` object

## Other responses

- `400`: The request is invalid
- `401`: Missing or invalid API key
- `402`: Refused for spend: the organization's balance is below the spend floor (insufficient_balance), or the API key's spend budget is used up (key_budget_exceeded)
- `403`: Refused, type permission_error. An inference call, a batch create or a file upload is refused while the account is unavailable, paused or under review (account_suspended, account_unavailable) or being verified (account_pending_verification), and an inference call names a model that takes an access request first (model_access_required). With permissions enabled, a role, key restriction, network rule or policy refuses the request (permission_denied, with permission and denied_by), or the model is outside the key's, role's or organization's model list (model_not_allowed, with permission, denied_by, model and allowed_models_hint); the OpenRelay-Required-Permission header names the permission.
- `413`: The upload exceeds the 200 MB limit
- `429`: Too many concurrent uploads; retry shortly
- `503`: The action could not be dispatched; retry

## Changes

- **2026-10-26** `7fe59d94a9f5`: 31 info
  - added the non-success response with the status `403`
  - added the optional property `error/allowed_models_hint` to the response with the `400` status
  - added the optional property `error/allowed_models_hint` to the response with the `401` status
  - added the optional property `error/allowed_models_hint` to the response with the `402` status
  - …27 more
- **2026-10-21** `dc9750cb25b5`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/openrelay/apis/openrelay-api/changes/v1/messages/post.md)

---

[API](https://skmtc.dev/openrelay/apis/openrelay-api.md) - [All operations](https://skmtc.dev/openrelay/apis/openrelay-api/llms.txt) - [OpenAPI document](https://skmtc.dev/openrelay/apis/openrelay-api/revisions/7fe59d94a9f5?raw)
