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

# Create a message (Anthropic)

> Anthropic Messages API on Grid models. Works with the official Anthropic SDKs and Claude Code by setting the base URL to `https://grid.x402compute.cc`. Same auth, x402 payment, routing and billing as `/v1/chat/completions`. `?beta=true` is accepted. Unsupported features (extended thinking with a budget, structured outputs, server tools, documents, image URLs, `top_p`, `top_k`, prefill, unknown fields) return `400 invalid_request_error`. See the [Anthropic API guide](/cloud/grid/anthropic-api).



## OpenAPI

````yaml POST /v1/messages
openapi: 3.1.0
info:
  title: x402 Singularity Layer API
  description: >-
    OpenAPI-backed reference for marketplace discovery, payment routes,
    webhooks, wallet-first auth, agent endpoints, and ERC-8004 flows.
  version: 1.0.0
servers:
  - url: https://api.x402layer.cc
security: []
tags:
  - name: Marketplace
    description: Public discovery and listing lookup
  - name: Public Endpoints
    description: Public endpoint metadata and hosted checkout context
  - name: Public Payment Links
    description: Hosted public payment-link lookup
  - name: Payments
    description: Hosted x402 payment challenge routes
  - name: Receipts
    description: Signed receipt lookup and verification helpers
  - name: Ratings
    description: Public listing ratings and authenticated rating actions
  - name: Webhooks
    description: Seller webhook management API
  - name: Agent Auth
    description: Wallet-first challenge and verification routes
  - name: Agent Endpoints
    description: Create, read, top up, and delete agent endpoints
  - name: ERC-8004
    description: Agent registry and registration lifecycle routes
  - name: Marketplace Agents
    description: Public ERC-8004 marketplace discovery routes
  - name: Compute Catalog
    description: Compute plans, regions, and OS catalog
  - name: Compute Instances
    description: Provision, inspect, extend, and destroy compute instances
  - name: Compute API Keys
    description: API keys for compute agent access
  - name: Fundraiser Campaigns
    description: List, view, create, and edit fundraiser campaigns
  - name: Fundraiser Contributions
    description: Record and list campaign contributions
  - name: Fundraiser Comments
    description: Campaign comment threads
  - name: Fundraiser Media
    description: Campaign image uploads and OG images
  - name: Enterprise
    description: >-
      Enterprise partner configuration, endpoint listing, revenue stats, and
      transaction ledger
  - name: Staking
    description: Agentic $SGL staking
  - name: SGL Grid
    description: >-
      Decentralized, confidential, OpenAI-compatible inference served by
      attested TEE nodes.
  - name: Compute Credits
    description: Prepaid USDC credit balance shared across Machines and Grid.
  - name: Agent Pods
    description: >-
      Deploy and manage hosted agents (Agent Pods), plus the pod's
      OpenAI-compatible adapter for external clients.
  - name: Agent Pods API
    description: >-
      The programmatic `/pods/v1` surface: create, drive and destroy Agent Pods
      with a single `X-API-Key`. Distinct from the Agent Pods dashboard routes,
      which expect a wallet signature or a browser session.
paths:
  /v1/messages:
    servers:
      - url: https://grid.x402compute.cc
    post:
      tags:
        - SGL Grid
      summary: Create a message (Anthropic)
      description: >-
        Anthropic Messages API on Grid models. Works with the official Anthropic
        SDKs and Claude Code by setting the base URL to
        `https://grid.x402compute.cc`. Same auth, x402 payment, routing and
        billing as `/v1/chat/completions`. `?beta=true` is accepted. Unsupported
        features (extended thinking with a budget, structured outputs, server
        tools, documents, image URLs, `top_p`, `top_k`, prefill, unknown fields)
        return `400 invalid_request_error`. See the [Anthropic API
        guide](/cloud/grid/anthropic-api).
      parameters:
        - name: x-api-key
          in: header
          required: false
          schema:
            type: string
            example: x402c_...
          description: >-
            Singularity Layer compute API key, billed to credits.
            `Authorization: Bearer x402c_...` or a session token also work. Omit
            to pay per request with x402 `X-Payment`.
        - name: anthropic-version
          in: header
          required: false
          schema:
            type: string
            example: '2023-06-01'
          description: Accepted, not enforced.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - messages
                - max_tokens
              properties:
                model:
                  type: string
                  example: qwen-2.5-32b
                  description: >-
                    A Grid model id from `GET /v1/models`, never a Claude model
                    id.
                max_tokens:
                  type: integer
                  minimum: 1
                  example: 512
                  description: >-
                    Lowered to fit the room left in the model's context. Output
                    is capped at 8192.
                messages:
                  type: array
                  description: >-
                    Conversation turns, `user` and `assistant`. Must not end
                    with an assistant message (no prefill). A mid-conversation
                    `system` message is folded into the user turn it follows.
                  items:
                    type: object
                    required:
                      - role
                      - content
                    properties:
                      role:
                        type: string
                        enum:
                          - user
                          - assistant
                      content:
                        oneOf:
                          - type: string
                          - type: array
                            items:
                              type: object
                              description: >-
                                A content block. Supported types: `text`,
                                `image` (base64 source, vision models only),
                                `tool_use`, `tool_result` (text content,
                                optional `is_error`).
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - text
                                    - image
                                    - tool_use
                                    - tool_result
                                text:
                                  type: string
                                source:
                                  type: object
                                  description: >-
                                    For `image`: `{type: "base64", media_type,
                                    data}`. URLs and Files API images are not
                                    supported.
                                id:
                                  type: string
                                name:
                                  type: string
                                input:
                                  type: object
                                tool_use_id:
                                  type: string
                                content:
                                  oneOf:
                                    - type: string
                                    - type: array
                                      items:
                                        type: object
                                is_error:
                                  type: boolean
                  example:
                    - role: user
                      content: Hello
                system:
                  oneOf:
                    - type: string
                    - type: array
                      items:
                        type: object
                  description: System prompt, as a string or text blocks.
                stream:
                  type: boolean
                  default: false
                  description: >-
                    Server-sent events in Anthropic order. Use it for long
                    replies.
                temperature:
                  type: number
                stop_sequences:
                  type: array
                  items:
                    type: string
                  description: >-
                    Applied by the Grid. Tokens the node generated past the
                    match are still billed.
                tools:
                  type: array
                  items:
                    type: object
                    properties:
                      name:
                        type: string
                      description:
                        type: string
                      input_schema:
                        type: object
                  description: >-
                    Your own tools with an `input_schema`. Server tools and
                    Anthropic-defined tools are refused.
                tool_choice:
                  type: object
                  description: >-
                    `{type: auto | any | tool | none}`.
                    `disable_parallel_tool_use: true` is refused.
                thinking:
                  type: object
                  description: >-
                    Accepted as a no-op for `adaptive`, `disabled`,
                    `between_tools`. `enabled` with `budget_tokens` is refused.
                metadata:
                  type: object
                  description: Accepted, no effect.
      responses:
        '200':
          description: The message, or an SSE stream when `stream` is true.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  type:
                    type: string
                    example: message
                  role:
                    type: string
                    example: assistant
                  model:
                    type: string
                  content:
                    type: array
                    items:
                      type: object
                      description: >-
                        A content block. Supported types: `text`, `image`
                        (base64 source, vision models only), `tool_use`,
                        `tool_result` (text content, optional `is_error`).
                      properties:
                        type:
                          type: string
                          enum:
                            - text
                            - image
                            - tool_use
                            - tool_result
                        text:
                          type: string
                        source:
                          type: object
                          description: >-
                            For `image`: `{type: "base64", media_type, data}`.
                            URLs and Files API images are not supported.
                        id:
                          type: string
                        name:
                          type: string
                        input:
                          type: object
                        tool_use_id:
                          type: string
                        content:
                          oneOf:
                            - type: string
                            - type: array
                              items:
                                type: object
                        is_error:
                          type: boolean
                  stop_reason:
                    type: string
                    enum:
                      - end_turn
                      - max_tokens
                      - stop_sequence
                      - tool_use
                      - refusal
                  stop_sequence:
                    type: string
                    nullable: true
                  usage:
                    type: object
                    properties:
                      input_tokens:
                        type: integer
                      output_tokens:
                        type: integer
                      cache_creation_input_tokens:
                        type: integer
                        example: 0
                      cache_read_input_tokens:
                        type: integer
                        example: 0
                      cost_usd:
                        type: number
                        description: 'Extra field: what this call was charged.'
            text/event-stream:
              schema:
                type: string
                description: >-
                  Events: message_start, content_block_start,
                  content_block_delta (text_delta, input_json_delta),
                  content_block_stop, message_delta, message_stop, ping, error.
        '400':
          description: >-
            `invalid_request_error`: unsupported field or feature, or the prompt
            does not fit the model's context.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
        '402':
          description: >-
            `billing_error`. Also carries the x402 fields (`x402Version`,
            `accepts`, `price_usd`) at the top level and a `WWW-Authenticate`
            header, so x402 clients can pay and retry.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
        '404':
          description: '`not_found_error`: the model is not served right now.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
        '429':
          description: '`rate_limit_error`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
        '504':
          description: >-
            `timeout_error`: a non-streaming reply ran past the sync window. The
            job continues and is billed; `job_id` is included and
            `x-should-retry: false` is set. Use `stream: true` for long replies.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
components:
  schemas:
    AnthropicError:
      type: object
      description: >-
        Anthropic-shaped error. The Grid's own detail (for example `code`,
        `context_limit`, `job_id`) rides along inside `error`.
      properties:
        type:
          type: string
          example: error
        error:
          type: object
          properties:
            type:
              type: string
              enum:
                - invalid_request_error
                - authentication_error
                - billing_error
                - permission_error
                - not_found_error
                - rate_limit_error
                - timeout_error
                - api_error
                - overloaded_error
            message:
              type: string
        request_id:
          type: string

````

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