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

# 建立訊息

> Claude Messages API for Anthropic-compatible payloads, tool use, and system prompts.



## OpenAPI

````yaml api-reference/openapi.json POST /v1/messages
openapi: 3.1.0
info:
  title: DGrid AI Gateway API
  description: >-
    A single, unified API to access 200+ leading AI models. OpenAI-, Claude-,
    and Gemini-compatible endpoints for chat, completions, embeddings, images,
    audio, and moderations.
  version: 1.0.0
  contact:
    name: DGrid AI
    url: https://dgrid.ai
servers:
  - url: https://api.dgrid.ai
    description: DGrid AI Gateway
security:
  - bearerAuth: []
paths:
  /v1/messages:
    post:
      tags:
        - Chat
      summary: Create message (Claude)
      description: >-
        Claude Messages API for Anthropic-compatible payloads, tool use, and
        system prompts.
      operationId: createMessage
      parameters:
        - name: anthropic-version
          in: header
          required: true
          schema:
            type: string
            default: '2023-06-01'
          description: Anthropic API version header.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - max_tokens
                - messages
              properties:
                model:
                  type: string
                  description: Model ID, such as `claude-3-5-sonnet-20241022`.
                  example: claude-3-5-sonnet-20241022
                max_tokens:
                  type: integer
                  description: Maximum output token count.
                  example: 1024
                messages:
                  type: array
                  description: Conversation message list.
                  items:
                    type: object
                    required:
                      - role
                      - content
                    properties:
                      role:
                        type: string
                        enum:
                          - user
                          - assistant
                        description: Message author role.
                      content:
                        description: Message content string or content blocks.
                        oneOf:
                          - type: string
                          - type: array
                            items:
                              type: object
                system:
                  type: string
                  description: System instructions.
                temperature:
                  type: number
                  description: Sampling temperature.
                top_p:
                  type: number
                  description: Top-p sampling.
                top_k:
                  type: integer
                  description: Top-k sampling.
                stop_sequences:
                  type: array
                  items:
                    type: string
                  description: Stop sequences.
                stream:
                  type: boolean
                  description: Enable streaming responses.
                tools:
                  type: array
                  items:
                    type: object
                  description: Tool schema definitions.
                tool_choice:
                  type: object
                  description: Tool selection strategy.
            example:
              model: claude-3-5-sonnet-20241022
              max_tokens: 1024
              messages:
                - role: user
                  content: Hello, Claude
      responses:
        '200':
          description: Claude message result.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    description: Message identifier.
                  type:
                    type: string
                    description: Always `message`.
                  role:
                    type: string
                    description: Always `assistant`.
                  content:
                    type: array
                    description: Returned content blocks.
                    items:
                      type: object
                      properties:
                        type:
                          type: string
                          description: '`text` or `tool_use`.'
                        text:
                          type: string
                          description: Text body when the content type is text.
                  model:
                    type: string
                    description: Model that produced the output.
                  stop_reason:
                    type: string
                    description: '`end_turn`, `max_tokens`, `stop_sequence`, or `tool_use`.'
                  usage:
                    type: object
                    description: Token usage metadata.
                    properties:
                      input_tokens:
                        type: integer
                      output_tokens:
                        type: integer
                      cache_creation_input_tokens:
                        type: integer
                      cache_read_input_tokens:
                        type: integer
        '400':
          $ref: '#/components/responses/BadRequest'
components:
  responses:
    BadRequest:
      description: Invalid request.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            param:
              type: string
            code:
              type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Your DGrid API key. All endpoints use `Authorization: Bearer
        <DGRID_API_KEY>`.

````