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

# Create a message (Anthropic Messages API)

> Drop-in compatible with Anthropic's Messages API. Authenticate with `x-api-key` (or `Authorization: Bearer`). A bare model id like `claude-haiku-4-5` routes to Anthropic; use `provider/model` for others. Set `stream: true` for SSE.



## OpenAPI

````yaml /openapi.yaml post /v1/messages
openapi: 3.1.0
info:
  title: Impossibl AI API
  version: 0.0.1
  description: >
    The Impossibl AI API is one API for all AI providers, OpenAI-compatible
    across OpenAI,

    Anthropic, Google, xAI, and more (`GET /v1/models` lists the full catalog),

    billed from a prepaid credit balance.


    Provider usage is billed at provider list prices with no usage markup.

    Prepaid credit purchases charge a separate fixed 5% platform fee before tax.


    **Agent quickstart**

    1. `POST /v1/accounts` — create a funded account; you get an API key and a
       signup-bonus balance in one call (no human step required).
    2. Call `POST /v1/chat/completions`, `POST /v1/responses`, or
       `POST /v1/audio/transcriptions` with
       `Authorization: Bearer <key>` and a `provider/model` id from `GET /v1/models`.
    3. Credits are deducted per request by token or audio-duration usage; check
    `GET /v1/account`.
servers:
  - url: https://api.impossibl.com
    description: Production
  - url: http://localhost:8787
    description: Local dev
security:
  - BearerKey: []
paths:
  /v1/messages:
    post:
      summary: Create a message (Anthropic Messages API)
      description: >-
        Drop-in compatible with Anthropic's Messages API. Authenticate with
        `x-api-key` (or `Authorization: Bearer`). A bare model id like
        `claude-haiku-4-5` routes to Anthropic; use `provider/model` for others.
        Set `stream: true` for SSE.
      operationId: createMessage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MessagesRequest'
      responses:
        '200':
          description: >
            A `message` object. When `stream: true`, the body is an SSE stream
            of

            Anthropic events (`message_start`, `content_block_delta`, …,
            `message_stop`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicMessage'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/InsufficientCredits'
        '404':
          $ref: '#/components/responses/UnknownModel'
        '502':
          $ref: '#/components/responses/UpstreamError'
        '503':
          $ref: '#/components/responses/ProviderNotConfigured'
      security:
        - BearerKey: []
        - ApiKeyHeader: []
components:
  schemas:
    MessagesRequest:
      type: object
      required:
        - model
        - max_tokens
        - messages
      properties:
        model:
          type: string
          example: claude-haiku-4-5
        max_tokens:
          type: integer
          description: Required by the Anthropic API.
        messages:
          type: array
          items:
            type: object
            properties:
              role:
                type: string
                enum:
                  - user
                  - assistant
              content:
                description: >-
                  A text string, or an array of content blocks (text, image,
                  tool_use, tool_result).
                oneOf:
                  - type: string
                  - type: array
                    items:
                      $ref: '#/components/schemas/AnthropicContentBlock'
        system:
          type: string
          description: Top-level system prompt.
        stream:
          type: boolean
          default: false
        temperature:
          type: number
        top_p:
          type: number
        top_k:
          type: integer
        stop_sequences:
          type: array
          items:
            type: string
        thinking:
          description: >-
            Anthropic thinking control, preserved on native Anthropic and
            Bedrock routes.
          oneOf:
            - type: object
              required:
                - type
                - budget_tokens
              properties:
                type:
                  type: string
                  const: enabled
                budget_tokens:
                  type: integer
                  minimum: 1024
            - type: object
              required:
                - type
              properties:
                type:
                  type: string
                  const: adaptive
                display:
                  type: string
                  enum:
                    - omitted
                    - summarized
            - type: object
              required:
                - type
              properties:
                type:
                  type: string
                  const: disabled
        output_config:
          type: object
          properties:
            effort:
              type: string
              enum:
                - low
                - medium
                - high
                - xhigh
                - max
        tools:
          type: array
          description: >-
            Tools the model may call (relay mode — the gateway does not execute
            them).
          items:
            type: object
            required:
              - name
              - input_schema
            properties:
              name:
                type: string
              description:
                type: string
              input_schema:
                type: object
                description: JSON Schema for the tool input.
        tool_choice:
          description: >-
            `{ type: auto }`, `{ type: any }`, `{ type: tool, name }`, or `{
            type: none }`.
          type: object
          properties:
            type:
              type: string
              enum:
                - auto
                - any
                - tool
                - none
            name:
              type: string
    AnthropicMessage:
      type: object
      description: Non-streaming Anthropic `message` response.
      properties:
        id:
          type: string
          example: msg_...
        type:
          type: string
          const: message
        role:
          type: string
          const: assistant
        model:
          type: string
        content:
          type: array
          description: Text blocks and, when the model calls a tool, tool_use blocks.
          items:
            type: object
            properties:
              type:
                type: string
                enum:
                  - text
                  - tool_use
              text:
                type: string
                description: Present on `text` blocks.
              id:
                type: string
                description: Present on `tool_use` blocks.
              name:
                type: string
                description: Present on `tool_use` blocks.
              input:
                type: object
                description: Parsed tool input on `tool_use` blocks.
        stop_reason:
          type: string
          enum:
            - end_turn
            - max_tokens
            - stop_sequence
            - tool_use
          nullable: true
        stop_sequence:
          type: string
          nullable: true
        usage:
          type: object
          properties:
            input_tokens:
              type: integer
            output_tokens:
              type: integer
    AnthropicContentBlock:
      type: object
      description: A content block on a message — text, image, tool_use, or tool_result.
      properties:
        type:
          type: string
          enum:
            - text
            - image
            - tool_use
            - tool_result
        text:
          type: string
          description: Present when `type` is `text`.
        source:
          type: object
          description: Present when `type` is `image`.
          properties:
            type:
              type: string
              enum:
                - base64
                - url
            media_type:
              type: string
              description: For base64, e.g. `image/png`.
            data:
              type: string
              description: For base64
              the raw base64 image data.: null
            url:
              type: string
              description: For url
              an http(s) URL.: null
        id:
          type: string
          description: tool_use block id.
        name:
          type: string
          description: tool_use tool name.
        input:
          type: object
          description: tool_use parsed input.
        tool_use_id:
          type: string
          description: tool_result — the tool_use id it answers.
        content:
          description: tool_result content — a string or nested blocks.
          oneOf:
            - type: string
            - type: array
              items:
                type: object
        is_error:
          type: boolean
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
              description: >-
                One of authentication_error, invalid_request_error,
                insufficient_quota, upstream_error, provider_not_configured.
  responses:
    BadRequest:
      description: Malformed request (bad JSON, or missing required fields).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: '`model` and `messages` are required'
              type: invalid_request_error
    Unauthorized:
      description: Missing or invalid API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: Invalid API key
              type: authentication_error
    InsufficientCredits:
      description: The account's credit balance is empty. Top up to continue.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: Insufficient credits. Top up to continue.
              type: insufficient_quota
    UnknownModel:
      description: The requested `model` id is not in the registry (see GET /v1/models).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: 'Unknown model: foo/bar'
              type: invalid_request_error
    UpstreamError:
      description: The upstream provider returned an error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: 'permission-denied: ...'
              type: upstream_error
    ProviderNotConfigured:
      description: The provider for this model has no API key configured on the gateway.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: 'Provider not configured: missing OPENAI_API_KEY'
              type: provider_not_configured
  securitySchemes:
    BearerKey:
      type: http
      scheme: bearer
      description: Gateway API key (`imp-rt-...`) from POST /v1/accounts or /v1/keys.
    ApiKeyHeader:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Gateway API key via the `x-api-key` header (what the Anthropic SDK
        sends).

````