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

# Create Message

> Anthropic-compatible Messages endpoint.

Auth:        x-api-key: rsk_<ULID>  (or Authorization: Bearer rsk_<ULID>)
Models:      any model this gateway serves, not only Anthropic's
Streaming:   set stream=true for Anthropic SSE events



## OpenAPI

````yaml /api/openapi.json post /v1/messages
openapi: 3.1.0
info:
  title: MeshAPI
  description: One key, all AI models.
  version: 0.1.0
servers:
  - url: https://api.meshapi.ai
security:
  - BearerAuth: []
paths:
  /v1/messages:
    post:
      tags:
        - Messages
      summary: Create Message
      description: >-
        Anthropic-compatible Messages endpoint.


        Auth:        x-api-key: rsk_<ULID>  (or Authorization: Bearer
        rsk_<ULID>)

        Models:      any model this gateway serves, not only Anthropic's

        Streaming:   set stream=true for Anthropic SSE events
      operationId: create_message
      parameters:
        - name: x-api-key
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Api-Key
        - in: header
          name: X-Mesh-Version
          required: false
          schema:
            type: string
            enum:
              - 2026-08
            default: 2026-08
          example: 2026-08
          description: >-
            Dated version of the API contract to pin this request to. Omit it
            and the request is served under `2026-08` — the oldest supported
            version, so an existing integration is never moved by a release. A
            malformed or unsupported value is rejected with `400
            invalid_api_version` rather than falling back silently. The version
            actually served is echoed as `X-Mesh-Version` on every response,
            including errors.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AnthropicMessagesRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - BearerAuth: []
components:
  schemas:
    AnthropicMessagesRequest:
      properties:
        model:
          type: string
          title: Model
        max_tokens:
          type: integer
          minimum: 1
          title: Max Tokens
        messages:
          items:
            $ref: '#/components/schemas/AnthropicMessage'
          type: array
          title: Messages
        system:
          anyOf:
            - type: string
            - items:
                $ref: '#/components/schemas/TextBlock'
              type: array
            - type: 'null'
          title: System
        temperature:
          anyOf:
            - type: number
              maximum: 1
              minimum: 0
            - type: 'null'
          title: Temperature
        top_p:
          anyOf:
            - type: number
              maximum: 1
              minimum: 0
            - type: 'null'
          title: Top P
        stop_sequences:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Stop Sequences
        stream:
          type: boolean
          title: Stream
          default: false
        metadata:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Metadata
        tools:
          anyOf:
            - items:
                $ref: '#/components/schemas/AnthropicTool'
              type: array
            - type: 'null'
          title: Tools
        tool_choice:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Tool Choice
        top_k:
          anyOf:
            - type: integer
            - type: 'null'
          title: Top K
        thinking:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Thinking
      type: object
      required:
        - model
        - max_tokens
        - messages
      title: AnthropicMessagesRequest
      example:
        max_tokens: 1024
        messages:
          - content: say hi
            role: user
        model: anthropic/claude-haiku-4.5
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    AnthropicMessage:
      properties:
        role:
          type: string
          enum:
            - user
            - assistant
            - system
          title: Role
        content:
          anyOf:
            - type: string
            - items:
                anyOf:
                  - $ref: '#/components/schemas/TextBlock'
                  - $ref: '#/components/schemas/ImageBlock'
                  - $ref: '#/components/schemas/ToolUseBlock'
                  - $ref: '#/components/schemas/ToolResultBlock'
              type: array
          title: Content
      type: object
      required:
        - role
        - content
      title: AnthropicMessage
      description: >-
        One turn.


        Anthropic's documented roles are ``user`` and ``assistant`` — system
        text is

        a top-level field, which is the biggest structural difference from the
        OpenAI

        shape. But ``system`` is accepted here as a THIRD role, because Claude
        Code

        actually sends one: a request captured against a real session carried

        ``roles: ["user", "system"]`` alongside a populated top-level
        ``system``.


        Rejecting it is not "being strict about the spec" — it is being
        incompatible

        with the single client this endpoint exists to serve, and it fails on
        the

        very first request with a 400 that names an internal field path. OpenAI
        has a

        native ``system`` role, so the mapping is direct and lossless.
    TextBlock:
      properties:
        type:
          type: string
          const: text
          title: Type
          default: text
        text:
          type: string
          title: Text
        cache_control:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Cache Control
      type: object
      required:
        - text
      title: TextBlock
      description: 'A ``{"type": "text", "text": ...}`` content block.'
    AnthropicTool:
      properties:
        name:
          type: string
          title: Name
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        input_schema:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Input Schema
      type: object
      required:
        - name
      title: AnthropicTool
      description: |-
        A tool definition. ``input_schema`` is Anthropic's name for what OpenAI
        calls ``function.parameters``.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    ImageBlock:
      properties:
        type:
          type: string
          const: image
          title: Type
          default: image
        source:
          $ref: '#/components/schemas/ImageSource'
        cache_control:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Cache Control
      type: object
      required:
        - source
      title: ImageBlock
    ToolUseBlock:
      properties:
        type:
          type: string
          const: tool_use
          title: Type
          default: tool_use
        id:
          type: string
          title: Id
        name:
          type: string
          title: Name
        input:
          additionalProperties: true
          type: object
          title: Input
        cache_control:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Cache Control
      type: object
      required:
        - id
        - name
      title: ToolUseBlock
      description: >-
        An assistant's tool invocation. ``input`` is a decoded object here,
        while

        OpenAI carries it as a JSON *string* in ``function.arguments``.
    ToolResultBlock:
      properties:
        type:
          type: string
          const: tool_result
          title: Type
          default: tool_result
        tool_use_id:
          type: string
          title: Tool Use Id
        content:
          anyOf:
            - type: string
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          title: Content
        is_error:
          type: boolean
          title: Is Error
          default: false
        cache_control:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Cache Control
      type: object
      required:
        - tool_use_id
      title: ToolResultBlock
      description: >-
        The caller's answer to a ``tool_use``.


        Structurally this is the biggest difference from OpenAI: Anthropic puts
        tool

        results in a **user** message as content blocks, while OpenAI uses
        dedicated

        ``role="tool"`` messages. One Anthropic user turn therefore expands into

        several OpenAI messages — see ``messages_request_to_chat``.
    ImageSource:
      properties:
        type:
          type: string
          enum:
            - base64
            - url
          title: Type
        media_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Media Type
        data:
          anyOf:
            - type: string
            - type: 'null'
          title: Data
        url:
          anyOf:
            - type: string
            - type: 'null'
          title: Url
      type: object
      required:
        - type
      title: ImageSource
      description: >-
        Anthropic carries images as a typed source object rather than a URL
        string.


        ``base64`` names its own ``media_type``; ``url`` is a plain remote
        reference.

        Both invert to an OpenAI ``image_url`` — see ``_image_block_to_url``,
        the

        inverse of ``_image_source`` (``app/providers/anthropic.py:100-123``).
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Enter your MeshAPI key (`rsk_...`) — sent as `Authorization: Bearer
        <key>`.

````