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

# Claude Messages

> Create a native Claude message with content blocks and stop reasons.

`POST /v1/messages`

Send the gateway token through `x-api-key` and set `anthropic-version` explicitly. Native requests include `model` and `messages`; the example explicitly supplies `max_tokens`, with system instructions at top-level `system`. The schema preserves the gateway's optional budget behavior; actual native provider requests should supply a model-supported budget.

Read nonstreaming `content[]` and check `stop_reason`. Values other than `end_turn` require appropriate handling: `tool_use` is not a final text answer and `max_tokens` may indicate truncation. With `stream: true`, use Claude SSE rather than a Chat / Responses event parser.

[The native Claude guide and complete TypeScript example](/en/guides/native-claude) include environment variables, run commands, and failure behavior. Only common text fields are expanded here; native extensions and conversion paths depend on channel support. `/v1/messages/count_tokens` is not enabled.

Verified revision: `d851a5faa49a00abaafd27bf91b311506fbfbc52`. Source files are recorded in this operation’s `x-source-files`.

[The Python native SSE and tool-loop example](/en/guides/native-claude-streaming) offers text and tool modes, preserving native result association and signatures.

[阅读中文](/zh/api-reference/claude-messages)

## Native cache and reasoning controls

The project DTO represents request-level and content-block `cache_control`, plus top-level `thinking`, `output_config`, and `context_management`. Actual support, TTLs, budgets, and modes depend on the channel and model. Claude `context_management` is a protocol-specific object and is not copied directly during Responses conversion; identical names do not imply equivalent semantics.

Native cache usage may contain `usage.cache_read_input_tokens` and `cache_creation_input_tokens`. Caching, reasoning, and compaction state do not automatically increase the model's context window. Preserve thinking / signature / redacted\_thinking continuation items according to the native protocol.

Added fields verified against revision `30a6d88a4`.

[Prompt caching](/en/guides/prompt-caching) · [Reasoning](/en/guides/reasoning-models) · [Context management](/en/guides/context-management)


## OpenAPI

````yaml openapi/relay.json POST /v1/messages
openapi: 3.0.3
info:
  title: API — Core inference API
  version: 0.5.0
  description: >-
    面向接入的精选规范，不是全部管理或供应商接口。 / Curated integration specification, not the entire
    management or provider API.
  license:
    name: AGPL-3.0-or-later
servers:
  - url: https://gateway.example.com
    description: >-
      Example only; replace with your gateway origin and optional path prefix,
      without /v1.
security:
  - BearerAuth: []
paths:
  /v1/messages:
    post:
      summary: Claude 原生消息 / Native Claude message
      description: >-
        精选文本接入字段；允许扩展字段不代表所有渠道支持。原生流式和工具扩展见指南。 / Selected text integration
        fields; accepting extensions does not guarantee channel support. See the
        guide for native streaming and tool boundaries.
      operationId: createClaudeMessage
      parameters:
        - name: anthropic-version
          in: header
          required: false
          description: 适配器缺省版本；建议显式发送 / Adapter fallback version; send explicitly.
          schema:
            type: string
            default: '2023-06-01'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - messages
              properties:
                model:
                  type: string
                  minLength: 1
                  example: YOUR_MODEL_ID
                max_tokens:
                  type: integer
                  minimum: 0
                  maximum: 1073741823
                  example: 256
                  description: >-
                    输出预算，实际范围依赖模型；调用原生供应商时应显式设置 / Output budget; model limits
                    apply. Set explicitly for native provider requests.
                system:
                  oneOf:
                    - type: string
                    - type: array
                      items:
                        type: object
                        required:
                          - type
                        properties:
                          type:
                            type: string
                          text:
                            type: string
                          id:
                            type: string
                          name:
                            type: string
                          input:
                            type: object
                            additionalProperties: true
                          tool_use_id:
                            type: string
                          content:
                            oneOf:
                              - type: string
                              - type: array
                                items:
                                  type: object
                                  additionalProperties: true
                          thinking:
                            type: string
                          signature:
                            type: string
                          data:
                            type: string
                          is_error:
                            type: boolean
                          cache_control:
                            type: object
                            description: >-
                              内容块缓存标记；具体支持取决于模型与渠道 / Content-block cache marker;
                              model and channel dependent
                            x-source-revision: 30a6d88a4fa41009755d0f157d1656ced297803d
                            additionalProperties: true
                        additionalProperties: true
                messages:
                  type: array
                  minItems: 1
                  items:
                    type: object
                    required:
                      - role
                      - content
                    properties:
                      role:
                        type: string
                        enum:
                          - user
                          - assistant
                      content:
                        oneOf:
                          - type: string
                          - type: array
                            items:
                              type: object
                              required:
                                - type
                              properties:
                                type:
                                  type: string
                                text:
                                  type: string
                                id:
                                  type: string
                                name:
                                  type: string
                                input:
                                  type: object
                                  additionalProperties: true
                                tool_use_id:
                                  type: string
                                content:
                                  oneOf:
                                    - type: string
                                    - type: array
                                      items:
                                        type: object
                                        additionalProperties: true
                                thinking:
                                  type: string
                                signature:
                                  type: string
                                data:
                                  type: string
                                is_error:
                                  type: boolean
                                cache_control:
                                  type: object
                                  description: >-
                                    内容块缓存标记；具体支持取决于模型与渠道 / Content-block cache
                                    marker; model and channel dependent
                                  x-source-revision: 30a6d88a4fa41009755d0f157d1656ced297803d
                                  additionalProperties: true
                              additionalProperties: true
                stream:
                  type: boolean
                  default: false
                tools:
                  type: array
                  items:
                    type: object
                    required:
                      - name
                      - input_schema
                    properties:
                      name:
                        type: string
                      description:
                        type: string
                      input_schema:
                        type: object
                        additionalProperties: true
                        description: >-
                          工具参数 Schema；示例额外执行本地校验 / Tool parameter schema;
                          examples also validate locally.
                    additionalProperties: true
                cache_control:
                  type: object
                  description: >-
                    原生缓存控制；依赖渠道，TTL 与断点限制不能跨供应商假定一致 / Native cache control;
                    channel dependent, TTL and breakpoint limits vary
                  x-source-revision: 30a6d88a4fa41009755d0f157d1656ced297803d
                  additionalProperties: true
                  example:
                    type: ephemeral
                thinking:
                  type: object
                  description: >-
                    原生推理配置；模式与预算由目标模型决定 / Native reasoning configuration; target
                    model determines modes and budgets
                  x-source-revision: 30a6d88a4fa41009755d0f157d1656ced297803d
                  additionalProperties: true
                output_config:
                  type: object
                  description: >-
                    原生输出配置，包含条件支持的 effort / Native output configuration,
                    including conditional effort support
                  x-source-revision: 30a6d88a4fa41009755d0f157d1656ced297803d
                  additionalProperties: true
                context_management:
                  type: object
                  description: >-
                    Claude 专用上下文编辑对象；Claude 转 Responses 不直接复制 / Claude-specific
                    context editing; not copied directly into Responses
                  x-source-revision: 30a6d88a4fa41009755d0f157d1656ced297803d
                  additionalProperties: true
              additionalProperties: true
      responses:
        '200':
          description: 检查原生完成状态及内容 / Check native completion status and content.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  type:
                    type: string
                  role:
                    type: string
                  model:
                    type: string
                  stop_reason:
                    type: string
                    nullable: true
                  content:
                    type: array
                    items:
                      type: object
                      required:
                        - type
                      properties:
                        type:
                          type: string
                        text:
                          type: string
                        id:
                          type: string
                        name:
                          type: string
                        input:
                          type: object
                          additionalProperties: true
                        tool_use_id:
                          type: string
                        content:
                          oneOf:
                            - type: string
                            - type: array
                              items:
                                type: object
                                additionalProperties: true
                        thinking:
                          type: string
                        signature:
                          type: string
                        data:
                          type: string
                        is_error:
                          type: boolean
                      additionalProperties: true
                  usage:
                    type: object
                    additionalProperties: true
                    properties:
                      cache_read_input_tokens:
                        type: integer
                        description: 原生缓存读数；可能缺失 / Native cache reads; may be absent
                        x-source-revision: 30a6d88a4fa41009755d0f157d1656ced297803d
                        minimum: 0
                      cache_creation_input_tokens:
                        type: integer
                        description: 原生缓存写入读数；可能缺失 / Native cache writes; may be absent
                        x-source-revision: 30a6d88a4fa41009755d0f157d1656ced297803d
                        minimum: 0
                additionalProperties: true
              example:
                type: message
                id: msg_example
                role: assistant
                stop_reason: end_turn
                content:
                  - type: text
                    text: Hello.
            text/event-stream:
              schema:
                type: string
              example: |+
                event: message_stop
                data: {"type":"message_stop"}

        default:
          description: >-
            网关或上游错误，结构可能随协议变化 / Gateway or upstream error; structure may vary by
            protocol.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
      security:
        - ClaudeApiKey: []
        - BearerAuth: []
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: 模型调用 API Key，不是控制台登录凭据 / Model API key, not console login credentials
    ClaudeApiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: 网关令牌 / Gateway token

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.