# Создать сообщение

> Создаёт сообщение в формате Anthropic Messages API. Поддерживает текст, изображения, PDF-файлы, инструменты и расширенное рассуждение.

## OpenAPI

```yaml
/openapi/openapi.yaml post /messages
openapi: 3.1.0
info:
  contact:
    email: support@openrouter.ai
    name: OpenRouter Support
    url: https://openrouter.ai/docs
  description: OpenAI-compatible API with additional OpenRouter features
  license:
    name: MIT
    url: https://opensource.org/licenses/MIT
  title: OpenRouter API
  version: 1.0.0
servers:
  - description: Production server
    url: https://openrouter.ai/api/v1
    x-speakeasy-server-id: production
security:
  - apiKey: []
tags:
  - description: API key management endpoints
    name: API Keys
  - description: Analytics and usage endpoints
    name: Analytics
  - description: Anthropic Messages endpoints
    name: Anthropic Messages
  - description: BYOK endpoints
    name: BYOK
  - description: Benchmarks endpoints
    name: Benchmarks
  - description: Chat completion endpoints
    name: Chat
  - description: Task classification market-share endpoints
    name: Classifications
  - description: Credit management endpoints
    name: Credits
  - description: >-
      Public OpenRouter usage datasets. Data returned by these endpoints is
      licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/):
      reuse and republish it, including commercially, with attribution to
      OpenRouter.
    name: Datasets
  - description: Text embedding endpoints
    name: Embeddings
  - description: Endpoint information
    name: Endpoints
  - description: Files endpoints
    name: Files
  - description: Generation history endpoints
    name: Generations
  - description: Guardrails endpoints
    name: Guardrails
  - description: Images endpoints
    name: Images
  - description: Model information endpoints
    name: Models
  - description: OAuth authentication endpoints
    name: OAuth
  - description: Observability endpoints
    name: Observability
  - description: Organization endpoints
    name: Organization
  - description: Presets endpoints
    name: Presets
  - description: Provider information endpoints
    name: Providers
  - description: Rerank endpoints
    name: Rerank
  - description: OpenAI-compatible Responses API endpoints
    name: Responses
  - description: SCIM endpoints
    name: SCIM
  - description: Speech-to-text endpoints
    name: STT
    x-displayName: Transcriptions
  - description: Text-to-speech endpoints
    name: TTS
    x-displayName: Speech
  - description: Video Generation endpoints
    name: Video Generation
  - description: Workspaces endpoints
    name: Workspaces
  - description: beta.Analytics endpoints
    name: beta.Analytics
externalDocs:
  description: OpenRouter Documentation
  url: https://openrouter.ai/docs
paths:
  /messages:
    post:
      tags:
        - Anthropic Messages
      summary: Create a message
      description: >-
        Creates a message using the Anthropic Messages API format. Supports
        text, images, PDFs, tools, and extended thinking.
      operationId: createMessages
      parameters:
        - description: >-
            Opt-in to surface routing metadata on the response under
            `openrouter_metadata`. Defaults to `disabled`. The legacy header
            `X-OpenRouter-Experimental-Metadata` is also accepted for backward
            compatibility.
          example: enabled
          in: header
          name: X-OpenRouter-Metadata
          required: false
          schema:
            $ref: '#/components/schemas/MetadataLevel'
      requestBody:
        content:
          application/json:
            example:
              max_tokens: 1024
              messages:
                - content: Hello, how are you?
                  role: user
              model: anthropic/claude-sonnet-4
            schema:
              $ref: '#/components/schemas/MessagesRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              example:
                container: null
                content:
                  - citations: []
                    text: >-
                      I'm doing well, thank you for asking! How can I help you
                      today?
                    type: text
                id: msg_abc123
                model: anthropic/claude-sonnet-4
                role: assistant
                stop_details: null
                stop_reason: end_turn
                stop_sequence: null
                type: message
                usage:
                  cache_creation: null
                  cache_creation_input_tokens: null
                  cache_read_input_tokens: null
                  inference_geo: null
                  input_tokens: 12
                  output_tokens: 18
                  output_tokens_details: null
                  server_tool_use: null
                  service_tier: standard
              schema:
                $ref: '#/components/schemas/MessagesResult'
            text/event-stream:
              example:
                data:
                  delta:
                    text: Hello
                    type: text_delta
                  index: 0
                  type: content_block_delta
                event: content_block_delta
              schema:
                $ref: '#/components/schemas/MessagesStreamingResponse'
              x-speakeasy-sse-sentinel: '[DONE]'
          description: Successful response
        '400':
          content:
            application/json:
              example:
                error:
                  message: 'Invalid request: messages is required'
                  type: invalid_request_error
                request_id: null
                type: error
              schema:
                $ref: '#/components/schemas/AnthropicMessagesErrorResponse'
          description: Invalid request error
        '401':
          content:
            application/json:
              example:
                error:
                  message: Invalid API key
                  type: authentication_error
                request_id: null
                type: error
              schema:
                $ref: '#/components/schemas/AnthropicMessagesErrorResponse'
          description: Authentication error
        '403':
          content:
            application/json:
              examples:
                guardrail-blocked:
                  summary: Guardrail blocked the request
                  value:
                    error:
                      message: 'Request blocked: prompt injection patterns detected'
                      type: permission_error
                    openrouter_metadata:
                      pipeline:
                        - name: regex_pi_detection
                          summary: >-
                            Blocked: prompt injection detected (1 pattern
                            matched)
                          type: guardrail
                    request_id: null
                    type: error
                insufficient-permissions:
                  summary: Insufficient permissions
                  value:
                    error:
                      message: Only management keys can perform this operation
                      type: permission_error
                    request_id: null
                    type: error
              schema:
                $ref: '#/components/schemas/AnthropicMessagesErrorResponse'
          description: Forbidden error
        '404':
          content:
            application/json:
              example:
                error:
                  message: Model not found
                  type: not_found_error
                request_id: gen-xxxxxxxxxxxxxxxxxxxxxxxx
                type: error
              schema:
                $ref: '#/components/schemas/AnthropicMessagesErrorResponse'
          description: Not found error
        '429':
          content:
            application/json:
              example:
                error:
                  message: Rate limit exceeded
                  type: rate_limit_error
                request_id: gen-xxxxxxxxxxxxxxxxxxxxxxxx
                type: error
              schema:
                $ref: '#/components/schemas/AnthropicMessagesErrorResponse'
          description: Rate limit error
        '500':
          content:
            application/json:
              example:
                error:
                  message: Internal server error
                  type: api_error
                request_id: gen-xxxxxxxxxxxxxxxxxxxxxxxx
                type: error
              schema:
                $ref: '#/components/schemas/AnthropicMessagesErrorResponse'
          description: API error
        '503':
          content:
            application/json:
              example:
                error:
                  message: Service temporarily overloaded
                  type: overloaded_error
                request_id: gen-xxxxxxxxxxxxxxxxxxxxxxxx
                type: error
              schema:
                $ref: '#/components/schemas/AnthropicMessagesErrorResponse'
          description: Overloaded error
        '529':
          content:
            application/json:
              example:
                error:
                  message: Provider is temporarily overloaded
                  type: overloaded_error
                request_id: gen-xxxxxxxxxxxxxxxxxxxxxxxx
                type: error
              schema:
                $ref: '#/components/schemas/AnthropicMessagesErrorResponse'
          description: Overloaded error
components:
  schemas:
    MetadataLevel:
      description: >-
        Opt-in level for surfacing routing metadata on the response under
        `openrouter_metadata`.
      enum:
        - disabled
        - enabled
      example: enabled
      type: string
    MessagesRequest:
      description: Request schema for Anthropic Messages API endpoint
      example:
        max_tokens: 1024
        messages:
          - content: Hello, how are you?
            role: user
        model: anthropic/claude-4.5-sonnet-20250929
        temperature: 0.7
      properties:
        cache_control:
          $ref: '#/components/schemas/AnthropicCacheControlDirective'
        context_management:
          properties:
            edits:
              items:
                oneOf:
                  - properties:
                      clear_at_least:
                        $ref: '#/components/schemas/AnthropicInputTokensClearAtLeast'
                      clear_tool_inputs:
                        anyOf:
                          - type: boolean
                          - items:
                              type: string
                            type: array
                          - type: 'null'
                      exclude_tools:
                        items:
                          type: string
                        type:
                          - array
                          - 'null'
                      keep:
                        $ref: '#/components/schemas/AnthropicToolUsesKeep'
                      trigger:
                        discriminator:
                          mapping:
                            input_tokens:
                              $ref: '#/components/schemas/AnthropicInputTokensTrigger'
                            tool_uses:
                              $ref: '#/components/schemas/AnthropicToolUsesTrigger'
                          propertyName: type
                        oneOf:
                          - $ref: '#/components/schemas/AnthropicInputTokensTrigger'
                          - $ref: '#/components/schemas/AnthropicToolUsesTrigger'
                      type:
                        enum:
                          - clear_tool_uses_20250919
                        type: string
                    required:
                      - type
                    type: object
                  - properties:
                      keep:
                        anyOf:
                          - $ref: '#/components/schemas/AnthropicThinkingTurns'
                          - properties:
                              type:
                                enum:
                                  - all
                                type: string
                            required:
                              - type
                            type: object
                          - enum:
                              - all
                            type: string
                      type:
                        enum:
                          - clear_thinking_20251015
                        type: string
                    required:
                      - type
                    type: object
                  - properties:
                      instructions:
                        type:
                          - string
                          - 'null'
                      pause_after_compaction:
                        type: boolean
                      trigger:
                        anyOf:
                          - allOf:
                              - $ref: >-
                                  #/components/schemas/AnthropicInputTokensTrigger
                              - properties: {}
                                type: object
                          - type: 'null'
                        example:
                          type: input_tokens
                          value: 100000
                      type:
                        enum:
                          - compact_20260112
                        type: string
                    required:
                      - type
                    type: object
              type: array
          type:
            - object
            - 'null'
        fallbacks:
          description: >-
            Fallback models to try if the primary model fails or refuses, in
            order. Handled by OpenRouter multi-model routing rather than
            Anthropic server-side fallbacks; cannot be combined with `models`.
            Each entry accepts only `model`. Maximum of 3 entries.
          example:
            - model: claude-opus-4-8
          items:
            $ref: '#/components/schemas/MessagesFallbackParam'
          type:
            - array
            - 'null'
        max_tokens:
          type: integer
        messages:
          items:
            $ref: '#/components/schemas/MessagesMessageParam'
          type:
            - array
            - 'null'
        metadata:
          properties:
            user_id:
              type:
                - string
                - 'null'
          type: object
        model:
          type: string
        models:
          items:
            type: string
          type: array
        output_config:
          $ref: '#/components/schemas/MessagesOutputConfig'
        plugins:
          description: >-
            Plugins you want to enable for this request, including their
            settings.
          items:
            discriminator:
              mapping:
                auto-beta-router:
                  $ref: '#/components/schemas/AutoBetaRouterPlugin'
                auto-router:
                  $ref: '#/components/schemas/AutoRouterPlugin'
                context-compression:
                  $ref: '#/components/schemas/ContextCompressionPlugin'
                file-parser:
                  $ref: '#/components/schemas/FileParserPlugin'
                fusion:
                  $ref: '#/components/schemas/FusionPlugin'
                moderation:
                  $ref: '#/components/schemas/ModerationPlugin'
                pareto-router:
                  $ref: '#/components/schemas/ParetoRouterPlugin'
                response-healing:
                  $ref: '#/components/schemas/ResponseHealingPlugin'
                web:
                  $ref: '#/components/schemas/WebSearchPlugin'
                web-fetch:
                  $ref: '#/components/schemas/WebFetchPlugin'
              propertyName: id
            oneOf:
              - $ref: '#/components/schemas/AutoRouterPlugin'
              - $ref: '#/components/schemas/AutoBetaRouterPlugin'
              - $ref: '#/components/schemas/ModerationPlugin'
              - $ref: '#/components/schemas/WebSearchPlugin'
              - $ref: '#/components/schemas/WebFetchPlugin'
              - $ref: '#/components/schemas/FileParserPlugin'
              - $ref: '#/components/schemas/ResponseHealingPlugin'
              - $ref: '#/components/schemas/ContextCompressionPlugin'
              - $ref: '#/components/schemas/ParetoRouterPlugin'
              - $ref: '#/components/schemas/FusionPlugin'
          type: array
        provider:
          $ref: '#/components/schemas/ProviderPreferences'
        route:
          $ref: '#/components/schemas/DeprecatedRoute'
        service_tier:
          type: string
        session_id:
          description: >-
            A unique identifier for grouping related requests (e.g., a
            conversation or agent workflow). When provided, OpenRouter uses it
            as the sticky routing key, routing all requests in the session to
            the same provider to maximize prompt cache hits. Also used for
            observability grouping. If provided in both the request body and the
            x-session-id header, the body value takes precedence. Maximum of 256
            characters.
          maxLength: 256
          type: string
        speed:
          allOf:
            - $ref: '#/components/schemas/AnthropicSpeed'
            - description: >-
                Controls output generation speed. When set to `fast`, uses a
                higher-speed inference configuration at premium pricing.
                Defaults to `standard` when omitted.
              example: fast
        stop_sequences:
          items:
            type: string
          type: array
        stop_server_tools_when:
          $ref: '#/components/schemas/StopServerToolsWhen'
        stream:
          type: boolean
        system:
          anyOf:
            - type: string
            - items:
                $ref: '#/components/schemas/AnthropicTextBlockParam'
              type: array
        temperature:
          format: double
          type: number
        thinking:
          oneOf:
            - properties:
                budget_tokens:
                  type: integer
                display:
                  $ref: '#/components/schemas/AnthropicThinkingDisplay'
                type:
                  enum:
                    - enabled
                  type: string
              required:
                - type
                - budget_tokens
              type: object
            - properties:
                type:
                  enum:
                    - disabled
                  type: string
              required:
                - type
              type: object
            - properties:
                display:
                  $ref: '#/components/schemas/AnthropicThinkingDisplay'
                type:
                  enum:
                    - adaptive
                  type: string
              required:
                - type
              type: object
        tool_choice:
          oneOf:
            - properties:
                disable_parallel_tool_use:
                  type: boolean
                type:
                  enum:
                    - auto
                  type: string
              required:
                - type
              type: object
            - properties:
                disable_parallel_tool_use:
                  type: boolean
                type:
                  enum:
                    - any
                  type: string
              required:
                - type
              type: object
            - properties:
                type:
                  enum:
                    - none
                  type: string
              required:
                - type
              type: object
            - properties:
                disable_parallel_tool_use:
                  type: boolean
                name:
                  type: string
                type:
                  enum:
                    - tool
                  type: string
              required:
                - type
                - name
              type: object
        tools:
          items:
            anyOf:
              - properties:
                  cache_control:
                    $ref: '#/components/schemas/AnthropicCacheControlDirective'
                  defer_loading:
                    type: boolean
                  description:
                    type: string
                  input_schema:
                    additionalProperties: {}
                    properties:
                      properties: {}
                      required:
                        items:
                          type: string
                        type:
                          - array
                          - 'null'
                      type:
                        default: object
                        type: string
                    type: object
                  name:
                    type: string
                  type:
                    enum:
                      - custom
                    type: string
                required:
                  - name
                  - input_schema
                type: object
              - properties:
                  cache_control:
                    $ref: '#/components/schemas/AnthropicCacheControlDirective'
                  name:
                    enum:
                      - bash
                    type: string
                  type:
                    enum:
                      - bash_20250124
                    type: string
                required:
                  - type
                  - name
                type: object
              - properties:
                  cache_control:
                    $ref: '#/components/schemas/AnthropicCacheControlDirective'
                  name:
                    enum:
                      - str_replace_editor
                    type: string
                  type:
                    enum:
                      - text_editor_20250124
                    type: string
                required:
                  - type
                  - name
                type: object
              - properties:
                  allowed_domains:
                    items:
                      type: string
                    type:
                      - array
                      - 'null'
                  blocked_domains:
                    items:
                      type: string
                    type:
                      - array
                      - 'null'
                  cache_control:
                    $ref: '#/components/schemas/AnthropicCacheControlDirective'
                  max_uses:
                    type:
                      - integer
                      - 'null'
                  name:
                    enum:
                      - web_search
                    type: string
                  type:
                    enum:
                      - web_search_20250305
                    type: string
                  user_location:
                    $ref: '#/components/schemas/AnthropicWebSearchToolUserLocation'
                required:
                  - type
                  - name
                type: object
              - properties:
                  allowed_callers:
                    $ref: '#/components/schemas/AnthropicAllowedCallers'
                  allowed_domains:
                    items:
                      type: string
                    type:
                      - array
                      - 'null'
                  blocked_domains:
                    items:
                      type: string
                    type:
                      - array
                      - 'null'
                  cache_control:
                    $ref: '#/components/schemas/AnthropicCacheControlDirective'
                  max_uses:
                    type:
                      - integer
                      - 'null'
                  name:
                    enum:
                      - web_search
                    type: string
                  type:
                    enum:
                      - web_search_20260209
                    type: string
                  user_location:
                    $ref: '#/components/schemas/AnthropicWebSearchToolUserLocation'
                required:
                  - type
                  - name
                type: object
              - properties:
                  allowed_callers:
                    $ref: '#/components/schemas/AnthropicAllowedCallers'
                  cache_control:
                    $ref: '#/components/schemas/AnthropicCacheControlDirective'
                  caching:
                    anyOf:
                      - $ref: '#/components/schemas/AnthropicCacheControlDirective'
                      - type: 'null'
                  defer_loading:
                    type: boolean
                  max_uses:
                    type: integer
                  model:
                    type: string
                  name:
                    enum:
                      - advisor
                    type: string
                  type:
                    enum:
                      - advisor_20260301
                    type: string
                required:
                  - type
                  - name
                  - model
                type: object
              - $ref: '#/components/schemas/BashServerTool'
              - $ref: '#/components/schemas/DatetimeServerTool'
              - $ref: '#/components/schemas/ImageGenerationServerTool_OpenRouter'
              - $ref: '#/components/schemas/MessagesSearchModelsServerTool'
              - $ref: '#/components/schemas/WebFetchServerTool'
              - $ref: '#/components/schemas/OpenRouterWebSearchServerTool'
              - additionalProperties: {}
                properties:
                  type:
                    type: string
                required:
                  - type
                type: object
              - $ref: '#/components/schemas/AnthropicToolSearchToolBm25'
              - $ref: '#/components/schemas/AnthropicToolSearchToolRegex'
              - $ref: '#/components/schemas/ShellServerTool_OpenRouter'
          type: array
        top_k:
          type: integer
        top_p:
          format: double
          type: number
        trace:
          $ref: '#/components/schemas/TraceConfig'
        user:
          description: >-
            A unique identifier representing your end-user, which helps
            distinguish between different users of your app. This allows your
            app to identify specific users in case of abuse reports, preventing
            your entire app from being affected by the actions of individual
            users. Maximum of 256 characters.
          maxLength: 256
          type: string
      required:
        - model
        - messages
      type: object
```