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

# Claude format

> Create Claude messages compatible with the Anthropic Messages protocol, supporting streaming and non-streaming responses

This endpoint is compatible with the Anthropic Claude Messages protocol for creating conversation messages.

## Features

* Supports both streaming (SSE) and non-streaming response modes
* Supports multimodal content (text, images, etc.)
* Supports tool use
* Supports thinking/reasoning mode configuration
* Supports cache control optimization

## Use cases

Suitable for scenarios requiring interaction with Claude models, including:

* Single-turn or multi-turn conversations
* Structured output (JSON Schema)
* Tool calling and function execution
* Code execution and container reuse

## Authentication

Include the `Authorization` header in the format `Bearer YOUR_API_KEY`.

<Note>
  The Claude format endpoint also requires the `anthropic-version` header, e.g. `2023-06-01`.
</Note>

## Quick example

<CodeGroup>
  ```python Python theme={null}
  import requests

  url = "https://api.haitoken.ai/v1/messages"
  headers = {
      "Authorization": "Bearer YOUR_API_KEY",
      "Content-Type": "application/json",
      "anthropic-version": "2023-06-01"
  }
  data = {
      "model": "claude-sonnet-4-0",
      "max_tokens": 1024,
      "messages": [
          {"role": "user", "content": "Hello, please introduce yourself"}
      ]
  }

  response = requests.post(url, json=data, headers=headers)
  print(response.json())
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.haitoken.ai/v1/messages', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json',
      'anthropic-version': '2023-06-01'
    },
    body: JSON.stringify({
      model: 'claude-sonnet-4-0',
      max_tokens: 1024,
      messages: [
        { role: 'user', content: 'Hello, please introduce yourself' }
      ]
    })
  });

  const data = await response.json();
  console.log(data);
  ```

  ```curl cURL theme={null}
  curl -X POST 'https://api.haitoken.ai/v1/messages' \
    -H 'Authorization: Bearer YOUR_API_KEY' \
    -H 'Content-Type: application/json' \
    -H 'anthropic-version: 2023-06-01' \
    -d '{
      "model": "claude-sonnet-4-0",
      "max_tokens": 1024,
      "messages": [
        {"role": "user", "content": "Hello, please introduce yourself"}
      ]
    }'
  ```
</CodeGroup>


## OpenAPI

````yaml en/api-reference/chat/claude/openapi.json POST /v1/messages
openapi: 3.0.1
info:
  title: Default Module
  description: ''
  version: 1.0.0
servers: []
security: []
tags: []
paths:
  /v1/messages:
    post:
      tags: []
      summary: Create Message
      description: Supports both streaming (SSE) and non-streaming response modes
      parameters:
        - name: anthropic-version
          in: header
          description: ''
          required: true
          schema:
            type: string
            example: '2023-06-01'
        - name: X-Api-Key
          in: header
          description: ''
          required: true
          schema:
            type: string
            example: YOUR_API_KEY
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ClaudeMessageRequest'
              description: ''
            examples: {}
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClaudeMessageResponse'
                description: >-
                  Claude Messages API non-streaming response

                  Reference:
                  https://platform.claude.com/docs/en/api/messages/create
          headers: {}
      deprecated: false
      security: []
components:
  schemas:
    ClaudeMessageRequest:
      type: object
      properties:
        max_tokens:
          type: integer
          description: Maximum number of output tokens (required)
        top_p:
          type: number
          description: Nucleus sampling, 0-1
        top_k:
          type: integer
          description: Top-K sampling
        stop_sequences:
          type: array
          items:
            type: string
          description: Stop sequences
        tool_choice:
          type: object
          properties: {}
          description: >-
            Tool choice configuration, can be a String or ClaudeToolChoice
            object
        cache_control:
          $ref: '#/components/schemas/ClaudeCacheControl'
          description: >-
            Top-level cache control configuration

            Automatically applies a cache_control marker to the last cacheable
            block in the request
        inference_geo:
          type: string
          description: >-
            Inference geographic region

            Specifies the geographic region for inference processing. If not
            specified, uses the workspace's default_inference_geo
        output_config:
          $ref: '#/components/schemas/ClaudeOutputConfig'
          description: >-
            Output configuration

            Configures model output format options, such as effort level and
            structured output format
        service_tier:
          type: string
          description: >-
            Service tier

            Determines whether to use priority capacity (if available) or
            standard capacity

            Possible values: "auto" / "standard_only"
        model:
          type: string
          description: Model name, e.g. claude-sonnet-4-0, claude-opus-4-0, etc.
        messages:
          type: array
          items:
            $ref: '#/components/schemas/ClaudeMessage'
            description: >-
              Claude message object

              The content field can be a String or List (multimodal content
              blocks)
          description: List of messages
        system:
          type: object
          properties: {}
          description: System instruction, can be a String or List<ClaudeSystemBlock>
        temperature:
          type: number
          description: Sampling temperature, 0.0-1.0
        stream:
          type: boolean
          description: Whether to enable streaming output
        thinking:
          $ref: '#/components/schemas/ClaudeThinkingConfig'
          description: Thinking/reasoning mode configuration
        tools:
          type: array
          items:
            $ref: '#/components/schemas/ClaudeTool'
            description: |-
              Claude tool definition (Tool / ToolUnion)
              Uses input_schema instead of OpenAI's function.parameters
              Reference: https://platform.claude.com/docs/en/api/messages/create
          description: List of tool definitions
        metadata:
          $ref: '#/components/schemas/ClaudeMetadata'
          description: Metadata
        container:
          type: string
          description: >-
            Container identifier, used for cross-request container reuse (code
            execution tool)
      required:
        - max_tokens
        - model
        - messages
    ClaudeMessageResponse:
      type: object
      properties:
        stop_reason:
          type: string
          description: >-
            Stop reason: end_turn / max_tokens / stop_sequence / tool_use /
            pause_turn / refusal

            Always output in the message_start event (even when null)
        stop_sequence:
          type: string
          description: |-
            Stop sequence that was matched (can be null)
            Always output in the message_start event (even when null)
        stop_details:
          $ref: '#/components/schemas/ClaudeStopDetails'
          description: >-
            Refusal stop details

            Structured information returned when the model refuses due to safety
            policy
        id:
          type: string
          description: Message ID (msg_ prefix)
        type:
          type: string
          description: Object type, always "message"
        role:
          type: string
          description: Role, always "assistant"
        content:
          type: array
          items:
            $ref: '#/components/schemas/ClaudeContentBlock'
            description: >-
              Claude response polymorphic content block

              Uses Jackson @JsonTypeInfo to distinguish subtypes by the type
              field
          description: List of response content blocks
        model:
          type: string
          description: Model name (the actual model that completed the task)
        container:
          $ref: '#/components/schemas/ClaudeContainer'
          description: >-
            Container information

            Container identifier for the code execution tool, used for
            cross-request reuse
        usage:
          $ref: '#/components/schemas/ClaudeUsage'
          description: Usage statistics
    ClaudeCacheControl:
      type: object
      properties:
        type:
          type: string
          description: Cache type, always "ephemeral"
        ttl:
          type: string
          description: |-
            Cache time-to-live (TTL)
            Possible values: "5m" (5 minutes) or "1h" (1 hour)
            Default: "5m"
    ClaudeOutputConfig:
      type: object
      properties:
        effort:
          type: string
          description: |-
            Reasoning effort level
            Possible values: "low" / "medium" / "high" / "xhigh" / "max"
        format:
          $ref: '#/components/schemas/JsonOutputFormat'
          description: |-
            JSON output format configuration (structured output)
            Used to specify the JSON Schema for Claude's output
    ClaudeMessage:
      type: object
      properties:
        role:
          type: string
          description: 'Message role: "user", "assistant", or "system"'
          enum:
            - USER
            - ASSISTANT
            - SYSTEM
        content:
          type: object
          properties: {}
          description: >-
            Message content, can be a String or List of polymorphic content
            blocks
    ClaudeThinkingConfig:
      type: object
      properties:
        budget_tokens:
          type: integer
          description: Thinking budget token count (required only when type="enabled")
        type:
          type: string
          description: 'Thinking mode type: enabled / disabled / adaptive'
        display:
          type: string
          description: >-
            Controls how thinking content is displayed in the response:
            "summarized" or "omitted"

            When set to summarized, thinking is restored to normal. When set to
            omitted, thinking content is redacted but a signature is returned
            for multi-turn continuity. Defaults to summarized.
    ClaudeTool:
      type: object
      properties:
        input_schema:
          type: array
          items:
            type: array
            items:
              type: array
              items:
                type: object
                properties: {}
          description: Tool input parameter definition in JSON Schema format
        allowed_callers:
          type: array
          items:
            type: string
          description: >-
            List of allowed callers

            Possible values: "direct" / "code_execution_20250825" /
            "code_execution_20260120"
        cache_control:
          $ref: '#/components/schemas/ClaudeCacheControl'
          description: Cache control configuration
        defer_loading:
          type: boolean
          description: >-
            Whether to defer loading

            When set to true, the tool is not included in the initial system
            prompt,

            and is only loaded when a tool_reference is returned via tool_search
        eager_input_streaming:
          type: boolean
          description: >-
            Whether to enable eager input streaming

            When true, tool input parameters are streamed incrementally and
            types are dynamically inferred

            When false, the complete JSON output is buffered even if
            fine-grained tool streaming is enabled

            When null (default), the default behavior based on the beta header
            is used
        input_examples:
          type: array
          items:
            $ref: '#/components/schemas/MapObject'
          description: |-
            List of tool input examples
            Helps the model understand how to use the tool
        name:
          type: string
          description: Tool name
        description:
          type: string
          description: Tool description
        type:
          type: string
          description: >-
            Tool type, only client tools need to be set to "custom"

            Server-side tools have their own type identifiers (e.g.
            "bash_20250124", "web_search_20250305", etc.)
        strict:
          type: boolean
          description: >-
            Strict mode

            When set to true, guarantees schema validation of tool name and
            input
    ClaudeMetadata:
      type: object
      properties:
        user_id:
          type: string
          description: ''
    ClaudeStopDetails:
      type: object
      properties:
        type:
          type: string
          description: Object type, always "refusal"
        category:
          type: string
          description: |-
            Policy category that triggered the refusal
            Possible values: "cyber" / "bio" / "reasoning_extraction"
            Null when the refusal does not correspond to a named category
        explanation:
          type: string
          description: >-
            Human-readable explanation of the refusal

            This text is not guaranteed to be stable. Null when no explanation
            is available for the category
    ClaudeContentBlock:
      type: object
      properties: {}
    ClaudeContainer:
      type: object
      properties:
        expires_at:
          type: string
          description: Container expiration time (ISO 8601 format)
        id:
          type: string
          description: Container identifier
    ClaudeUsage:
      type: object
      properties:
        input_tokens:
          type: integer
          description: ''
        output_tokens:
          type: integer
          description: ''
        cache_creation_input_tokens:
          type: integer
          description: ''
        cache_read_input_tokens:
          type: integer
          description: ''
        cache_creation:
          $ref: '#/components/schemas/ClaudeCacheCreation'
          description: Cache creation details, categorized by TTL
        inference_geo:
          type: string
          description: Inference geographic region
        output_tokens_details:
          $ref: '#/components/schemas/ClaudeOutputTokensDetails'
          description: >-
            Output token details, broken down by category (read-only, for
            observability)
        server_tool_use:
          $ref: '#/components/schemas/ClaudeServerToolUsage'
          description: Server-side tool usage statistics
        service_tier:
          type: string
          description: |-
            Service tier
            Possible values: "standard" / "priority" / "batch"
    JsonOutputFormat:
      type: object
      properties:
        schema:
          type: array
          items:
            type: array
            items:
              type: array
              items:
                type: object
                properties: {}
          description: JSON Schema definition
        type:
          type: string
          description: Format type, always "json_schema"
    MapObject:
      type: object
      properties:
        key:
          $ref: '#/components/schemas/key'
    ClaudeCacheCreation:
      type: object
      properties:
        ephemeral_5m_input_tokens:
          type: integer
          description: Number of input tokens used to create 5-minute cache entries
        ephemeral_1h_input_tokens:
          type: integer
          description: Number of input tokens used to create 1-hour cache entries
    ClaudeOutputTokensDetails:
      type: object
      properties:
        thinking_tokens:
          type: integer
          description: >-
            Number of output tokens generated by the model as internal reasoning

            Includes thinking block delimiter tokens

            Always ≤ output_tokens; output_tokens - thinking_tokens ≈
            non-reasoning output
    ClaudeServerToolUsage:
      type: object
      properties:
        web_search_requests:
          type: integer
          description: Number of web search tool requests
        web_fetch_requests:
          type: integer
          description: Number of web fetch tool requests
    key:
      type: object
      properties: {}

````