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

# Claude 聊天

> Anthropic Claude Messages API 格式的请求。
需要在请求头中包含 `anthropic-version`。




## OpenAPI

````yaml /api.json post /v1/messages
openapi: 3.0.1
info:
  title: TKHub API
  description: TKHub 平台 API 接口文档
  version: 1.0.0
servers:
  - url: https://api.tkhub.ai
    description: 生产环境
  - url: https://api-test.tkhub.ai
    description: 测试环境
security:
  - bearerAuth: []
paths:
  /v1/messages:
    post:
      tags:
        - Claude格式(Messages)
      summary: Claude 聊天
      description: |
        Anthropic Claude Messages API 格式的请求。
        需要在请求头中包含 `anthropic-version`。
      operationId: createMessage
      parameters:
        - name: anthropic-version
          in: header
          description: Anthropic API 版本
          required: true
          example: ''
          schema:
            type: string
            example: '2023-06-01'
        - name: x-api-key
          in: header
          description: Anthropic API Key (可选，也可使用 Bearer Token)
          required: false
          example: ''
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ClaudeRequest'
            examples: {}
      responses:
        '200':
          description: 成功创建响应
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClaudeResponse'
          headers: {}
      deprecated: false
      security:
        - BearerAuth: []
components:
  schemas:
    ClaudeRequest:
      type: object
      required:
        - model
        - messages
        - max_tokens
      properties:
        model:
          type: string
          example: claude-3-opus-20240229
        messages:
          type: array
          items:
            $ref: '#/components/schemas/ClaudeMessage'
        system:
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                properties: {}
        max_tokens:
          type: integer
          minimum: 1
        temperature:
          type: number
          minimum: 0
          maximum: 1
        top_p:
          type: number
        top_k:
          type: integer
        stream:
          type: boolean
        stop_sequences:
          type: array
          items:
            type: string
        tools:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
              description:
                type: string
              input_schema:
                type: object
                properties: {}
        tool_choice:
          oneOf:
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - auto
                    - any
                    - tool
                name:
                  type: string
        thinking:
          type: object
          properties:
            type:
              type: string
              enum:
                - enabled
                - disabled
            budget_tokens:
              type: integer
        metadata:
          type: object
          properties:
            user_id:
              type: string
    ClaudeResponse:
      type: object
      properties:
        id:
          type: string
        type:
          type: string
          example: message
        role:
          type: string
          example: assistant
        content:
          type: array
          items:
            type: object
            properties:
              type:
                type: string
              text:
                type: string
        model:
          type: string
        stop_reason:
          type: string
          enum:
            - end_turn
            - max_tokens
            - stop_sequence
            - tool_use
        usage:
          type: object
          properties:
            input_tokens:
              type: integer
            output_tokens:
              type: integer
            cache_creation_input_tokens:
              type: integer
            cache_read_input_tokens:
              type: integer
    ClaudeMessage:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - user
            - assistant
        content:
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                properties:
                  type:
                    type: string
                    enum:
                      - text
                      - image
                      - tool_use
                      - tool_result
                  text:
                    type: string
                  source:
                    type: object
                    properties:
                      type:
                        type: string
                        enum:
                          - base64
                          - url
                      media_type:
                        type: string
                      data:
                        type: string
                      url:
                        type: string
                  id:
                    type: string
                  name:
                    type: string
                  input:
                    type: object
                    properties: {}
                  tool_use_id:
                    type: string
                  content:
                    type: string
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: |
        使用 Bearer Token 认证。
        格式: `Authorization: Bearer sk-xxxxxx`

````