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

> ## Agent Instructions
> Orq.ai is the control plane for model and MCP traffic: one key reaches the workspace's enabled models, MCP servers, and resources. The setup depends on where the agent runs.
> Hosted assistant (ChatGPT, claude.ai, a hosted sandbox): install nothing. Tell the human to add https://my.orq.ai/v2/mcp as a remote MCP connector and finish the Orq.ai sign-in. With OAuth, send no Authorization header; otherwise send an API key as a bearer token.
> Local coding agent (Claude Code, Codex, Cursor, OpenCode): run `curl -fsSL https://cli.orq.ai/install.sh | sh`. It installs the CLI and runs `orq setup`, which signs in, writes a project-scoped key to `~/.orq/env`, and wires the detected agents through the AI Gateway. It can also add the Orq MCP server and Orq Skills, the workflows for agents, evaluations, and traces: https://docs.orq.ai/ai-studio/integrations/code-assistants/orq-skills.md. Verify with `orq status`.
> Headless or CI: read `ORQ_API_KEY` from the environment; a human creates the key at https://docs.orq.ai/ai-studio/organization/api-keys.md.
> Send model traffic to https://my.orq.ai/v3/router with `Authorization: Bearer $ORQ_API_KEY`; the Anthropic SDK uses https://my.orq.ai/v3/anthropic. New integrations go on `/v3/router`: `/v2/router` stays published for backward compatibility, and `orq.prompt` works only on `/v2/router/chat/completions`.
> Enable a model for the workspace and use its exact `provider/model` id. `POST /v2/workspace-models` enables a model, and a call fails while the workspace has neither credits nor a provider key.
> On `/chat/completions`, a reasoning model rejects `tools` with a `reasoning_effort` other than `none`; `/responses` keeps reasoning.
> On a failure, branch on `error.code` and follow `error.doc_url`; a budget rejection answers 429.

# Count message tokens

> Reference for POST /v3/anthropic/v1/messages/count_tokens: count the input tokens a Messages request consumes before sending it.

> [!NOTE]
>
> **Related guide**: Anthropic Messages API. See the [Anthropic Messages API guide](https://docs.orq.ai/ai-gateway/features/anthropic-messages-api.md) for token counting against a resolved model.


## OpenAPI

````yaml post /v3/anthropic/v1/messages/count_tokens
openapi: 3.1.0
info:
  title: orq.ai API
  version: '2.0'
  description: orq.ai API documentation
servers:
  - url: https://my.orq.ai
security:
  - ApiKey: []
tags:
  - name: Chunking
    description: Split text into smaller chunks for retrieval and generation workflows.
  - name: File Systems
    description: >-
      Create and manage persistent file systems that agents and MCP clients read
      from and write to.
  - name: Knowledge Bases
    description: Create and manage knowledge bases used by agents and retrieval workflows.
  - name: Memory Stores
    description: Create and manage memory stores, memories, and memory documents.
  - name: Evals
    description: Run an evaluator against a conversation and its result
  - description: >-
      API keys authenticate programmatic access to the workspace. They expose
      opaque tokens, per-domain access grants, and budget and rate-limit
      constraints.
    name: API keys
  - name: Logs
    description: >-
      OpenTelemetry log query API. Search, filter, aggregate, and facet log
      records ingested via OTLP.
  - name: Reporting
    description: >-
      GenAI reporting API over canonical analytics rollups. Accepts a metric
      name, time range, grain, group-by, and filters; returns a typed time
      series and optional totals.
  - name: Telemetry
    description: >-
      Unified query envelope for traces, metrics, and logs. One request shape,
      one filter dialect, and one response shape per source, validated by a
      per-source registry.
  - name: Telemetry Destinations
    description: >-
      OpenTelemetry destinations that receive a copy of the workspace's traces
      over OTLP/HTTP.
  - name: Traces
    description: >-
      Query and inspect ingested trace data: search trace summaries, aggregate
      metrics, and read individual traces and their spans.
  - name: Views
    description: Saved filters and columns for workspace observability pages.
  - name: Datasets
    description: >-
      Datasets store test cases and expected outputs used for evaluation and
      optimization workflows.
  - name: Experiments
    description: >-
      Create and run experiments: dataset rows against task columns, evaluators,
      and annotations.
  - description: List models available through the AI Router.
    name: Models
  - name: Agents
    description: External A2A agents registered for invocation through the ORQ AI Gateway.
  - name: Alerts
    description: >-
      Alerts evaluate a telemetry metric on a fixed interval and fire
      notifications through notifiers when the value breaches a threshold. Each
      breach opens a trigger that tracks the incident until the value recovers.
  - name: Annotation Queues
    description: Annotation queues collect spans for human review.
  - name: Audit Log Destinations
    description: >-
      Signed webhook destinations that receive workspace audit log events, for
      SIEM and compliance pipelines.
  - name: Budgets
    description: >-
      Budgets govern spend, token usage, and request rate across workspace,
      project, identity, API key, provider, model, factory, and category-default
      scopes. Category defaults provide a separate allowance for each entity; an
      active individual budget replaces its category default. Every applicable
      budget is enforced, and the most restrictive limit applies per dimension.
  - name: Environments
    description: Reusable workspace- and project-scoped deployment environments.
  - name: Files
    description: File upload and retrieval operations.
  - name: Guardrail Rules
    description: >-
      Guardrail Rules conditionally enforce evaluators and plugins for AI
      Gateway traffic. Rules may be scoped to a project or the whole workspace.
  - name: Hub
    description: Hub items are reusable templates available to a workspace.
  - name: Identities
    description: >-
      Identities represent end users from your system for usage and engagement
      tracking.
  - name: Management keys
    description: >-
      Management keys are workspace-scoped credentials that authenticate
      programmatic access to workspace administration surfaces (API keys,
      budgets). Unlike project-scoped API keys, a management key always operates
      at the workspace level.
  - name: MCP Gateway
    description: >-
      Register upstream MCP servers, discover and sync their tools, and assemble
      gateways that expose a curated tool surface to MCP clients.
  - name: Model Catalog
    description: >-
      Browse the orq.ai model catalog: every model orq offers, across every
      provider, with pricing, capabilities and benchmark data. List endpoints
      only return models that are not deprecated. This API is public, requires
      no authentication, and is rate limited to 120 requests per minute per IP.
      Responses carry a 5-minute cache-control max-age.
  - name: Model Fusions
    description: >-
      Model Fusions combine independent model answers through a panel, judge,
      and optional synthesizer.
  - name: Monitors
    description: >-
      Monitors are custom observability dashboards for traces, runtime metrics,
      and logs. Each monitor holds widgets that chart one telemetry query. List
      the metrics, operations, and dimensions available to your workspace with
      `GET /v3/telemetry/capabilities`, or start from a preset with `GET
      /v2/monitors/presets`.
  - name: Notifiers
    description: Notifier destinations used to send delivery and workflow notifications.
  - name: Projects
    description: Projects organize resources within a workspace
  - name: Routing Rules
    description: >-
      Routing Rules conditionally select models and enforce request plugins for
      AI Gateway traffic. Rules are evaluated by ascending priority and may be
      scoped to a project or the whole workspace.
  - name: Threads
    description: Threads group related trace invocations and their aggregate usage
  - name: Skills
    description: >-
      Skills are modular instructions you can use to codify processes and
      conventions
  - name: Smart Routers
    description: >-
      Create and manage workspace Smart Routers. A Smart Router selects a model
      from an eligible pool for each request according to a quality, balanced,
      or cost profile.
  - name: Users
    description: >-
      Workspace user administration. Requires a Management Key with user
      permissions or an authenticated workspace admin session. Standard API keys
      are not supported.
  - name: Webhooks
    description: >-
      Create and manage webhooks that deliver workspace events to external HTTPS
      endpoints.
  - name: Workspaces
    description: >-
      A workspace is the tenant. Create is called from a user session during
      onboarding; Get, List, and Update are the public management surface.
  - name: Workspace Security
    description: >-
      Workspace-level domain verification and IP allowlist controls. These
      operations are restricted to workspace administrators.
  - name: Workspace Settings
    description: >-
      Workspace-level settings managed with a workspace credential. A workspace
      is the tenant, so these settings are a singleton — there is nothing to
      create or delete, only read and update.
  - description: Search Gateway with managed credits or BYOK.
    name: Web Search
  - name: Live Sessions
  - name: Responses
  - description: Run agents on a cron cadence. Minimum firing interval is 1 hour.
    name: Agent Schedules
  - name: Embeddings
  - description: Beta. Run typed classification questions against a classify model.
    name: Classify
  - description: Beta. Run classification decisions with the classify contract.
    name: Decisions
  - description: >-
      Run large offline workloads as JSONL batches and download
      OpenAI-compatible result files.
    name: Batches
  - name: Anthropic Messages
    description: >-
      Anthropic Messages-compatible endpoints: messages, token counting, and
      models.
externalDocs:
  url: https://docs.orq.ai
  description: orq.ai Documentation
paths:
  /v3/anthropic/v1/messages/count_tokens:
    post:
      tags:
        - Anthropic Messages
      summary: Count message tokens
      description: >-
        Counts the input tokens a Messages request consumes, so a caller can
        size a request before sending it. A model that cannot count tokens
        answers 400 invalid_request_error.
      operationId: count-anthropic-message-tokens
      requestBody:
        content:
          application/json:
            schema:
              additionalProperties: false
              properties:
                cache_control:
                  $ref: '#/components/schemas/PublicAnthropicCacheControl'
                  description: Applies a cache_control marker to the last cacheable block.
                messages:
                  description: Conversation so far, oldest turn first.
                  items:
                    additionalProperties: false
                    properties:
                      content:
                        anyOf:
                          - description: Plain text content.
                            type: string
                          - items:
                              description: >-
                                Content block. The type field selects the block,
                                and provider-specific block types are forwarded
                                unchanged.
                              oneOf:
                                - description: Text content.
                                  properties:
                                    cache_control:
                                      description: >-
                                        Prompt-cache marker. Placed on the last
                                        block whose prefix should be cached.
                                      properties:
                                        ttl:
                                          description: Cache lifetime. Defaults to 5m.
                                          enum:
                                            - 5m
                                            - 1h
                                          type: string
                                        type:
                                          description: Cache control type.
                                          enum:
                                            - ephemeral
                                          type: string
                                      required:
                                        - type
                                      type: object
                                    citations:
                                      additionalProperties: true
                                      description: Source citations attached to the block.
                                      type: object
                                    text:
                                      description: Text to send.
                                      type: string
                                    type:
                                      description: Block type.
                                      enum:
                                        - text
                                      type: string
                                  required:
                                    - type
                                    - text
                                  title: Text
                                  type: object
                                - description: An image, supplied as base64 data or a URL.
                                  properties:
                                    cache_control:
                                      description: >-
                                        Prompt-cache marker. Placed on the last
                                        block whose prefix should be cached.
                                      properties:
                                        ttl:
                                          description: Cache lifetime. Defaults to 5m.
                                          enum:
                                            - 5m
                                            - 1h
                                          type: string
                                        type:
                                          description: Cache control type.
                                          enum:
                                            - ephemeral
                                          type: string
                                      required:
                                        - type
                                      type: object
                                    source:
                                      properties:
                                        data:
                                          description: >-
                                            Base64-encoded image bytes, when type is
                                            base64.
                                          type: string
                                        media_type:
                                          description: Image MIME type, for example image/png.
                                          type: string
                                        type:
                                          description: 'Source kind: base64 or url.'
                                          enum:
                                            - base64
                                            - url
                                          type: string
                                        url:
                                          description: Image URL, when type is url.
                                          type: string
                                      required:
                                        - type
                                      type: object
                                    type:
                                      description: Block type.
                                      enum:
                                        - image
                                      type: string
                                  required:
                                    - type
                                    - source
                                  title: Image
                                  type: object
                                - description: A PDF or text document.
                                  properties:
                                    cache_control:
                                      description: >-
                                        Prompt-cache marker. Placed on the last
                                        block whose prefix should be cached.
                                      properties:
                                        ttl:
                                          description: Cache lifetime. Defaults to 5m.
                                          enum:
                                            - 5m
                                            - 1h
                                          type: string
                                        type:
                                          description: Cache control type.
                                          enum:
                                            - ephemeral
                                          type: string
                                      required:
                                        - type
                                      type: object
                                    context:
                                      description: Context about the document.
                                      type: string
                                    source:
                                      properties:
                                        data:
                                          description: Base64-encoded document bytes.
                                          type: string
                                        media_type:
                                          description: >-
                                            Document MIME type, for example
                                            application/pdf.
                                          type: string
                                        text:
                                          description: Document text, when type is text.
                                          type: string
                                        type:
                                          description: >-
                                            Source kind: base64, text, url, or
                                            content.
                                          enum:
                                            - base64
                                            - text
                                            - url
                                            - content
                                          type: string
                                        url:
                                          description: Document URL, when type is url.
                                          type: string
                                      required:
                                        - type
                                      type: object
                                    title:
                                      description: Document title.
                                      type: string
                                    type:
                                      description: Block type.
                                      enum:
                                        - document
                                      type: string
                                  required:
                                    - type
                                    - source
                                  title: Document
                                  type: object
                                - description: >-
                                    A tool call from an earlier assistant turn,
                                    echoed back to the model.
                                  properties:
                                    id:
                                      description: Tool call ID.
                                      type: string
                                    input:
                                      additionalProperties: true
                                      description: Arguments for the tool call.
                                      type: object
                                    name:
                                      description: Tool name.
                                      type: string
                                    type:
                                      description: Block type.
                                      enum:
                                        - tool_use
                                      type: string
                                  required:
                                    - type
                                    - id
                                    - name
                                  title: Tool use
                                  type: object
                                - description: >-
                                    The result of a tool call, returned to the
                                    model.
                                  properties:
                                    cache_control:
                                      description: >-
                                        Prompt-cache marker. Placed on the last
                                        block whose prefix should be cached.
                                      properties:
                                        ttl:
                                          description: Cache lifetime. Defaults to 5m.
                                          enum:
                                            - 5m
                                            - 1h
                                          type: string
                                        type:
                                          description: Cache control type.
                                          enum:
                                            - ephemeral
                                          type: string
                                      required:
                                        - type
                                      type: object
                                    content:
                                      anyOf:
                                        - description: Result text.
                                          type: string
                                        - items:
                                            oneOf:
                                              - description: Text content.
                                                properties:
                                                  cache_control:
                                                    description: >-
                                                      Prompt-cache marker. Placed on the last
                                                      block whose prefix should be cached.
                                                    properties:
                                                      ttl:
                                                        description: Cache lifetime. Defaults to 5m.
                                                        enum:
                                                          - 5m
                                                          - 1h
                                                        type: string
                                                      type:
                                                        description: Cache control type.
                                                        enum:
                                                          - ephemeral
                                                        type: string
                                                    required:
                                                      - type
                                                    type: object
                                                  citations:
                                                    additionalProperties: true
                                                    description: Source citations attached to the block.
                                                    type: object
                                                  text:
                                                    description: Text to send.
                                                    type: string
                                                  type:
                                                    description: Block type.
                                                    enum:
                                                      - text
                                                    type: string
                                                required:
                                                  - type
                                                  - text
                                                title: Text
                                                type: object
                                              - description: >-
                                                  An image, supplied as base64 data or a
                                                  URL.
                                                properties:
                                                  cache_control:
                                                    description: >-
                                                      Prompt-cache marker. Placed on the last
                                                      block whose prefix should be cached.
                                                    properties:
                                                      ttl:
                                                        description: Cache lifetime. Defaults to 5m.
                                                        enum:
                                                          - 5m
                                                          - 1h
                                                        type: string
                                                      type:
                                                        description: Cache control type.
                                                        enum:
                                                          - ephemeral
                                                        type: string
                                                    required:
                                                      - type
                                                    type: object
                                                  source:
                                                    properties:
                                                      data:
                                                        description: >-
                                                          Base64-encoded image bytes, when type is
                                                          base64.
                                                        type: string
                                                      media_type:
                                                        description: Image MIME type, for example image/png.
                                                        type: string
                                                      type:
                                                        description: 'Source kind: base64 or url.'
                                                        enum:
                                                          - base64
                                                          - url
                                                        type: string
                                                      url:
                                                        description: Image URL, when type is url.
                                                        type: string
                                                    required:
                                                      - type
                                                    type: object
                                                  type:
                                                    description: Block type.
                                                    enum:
                                                      - image
                                                    type: string
                                                required:
                                                  - type
                                                  - source
                                                title: Image
                                                type: object
                                          type: array
                                      description: >-
                                        Result content: a string, or an array of
                                        text and image blocks.
                                    is_error:
                                      description: Whether the tool call failed.
                                      type: boolean
                                    tool_use_id:
                                      description: ID of the tool call this result answers.
                                      type: string
                                    type:
                                      description: Block type.
                                      enum:
                                        - tool_result
                                      type: string
                                  required:
                                    - type
                                    - tool_use_id
                                  title: Tool result
                                  type: object
                                - description: >-
                                    Reasoning from an earlier assistant turn,
                                    with its signature.
                                  properties:
                                    signature:
                                      description: >-
                                        Signature that lets the model verify the
                                        reasoning was its own.
                                      type: string
                                    thinking:
                                      description: Reasoning text.
                                      type: string
                                    type:
                                      description: Block type.
                                      enum:
                                        - thinking
                                      type: string
                                  required:
                                    - type
                                    - thinking
                                  title: Thinking
                                  type: object
                                - description: >-
                                    Opaque reasoning the provider encrypted
                                    before returning it.
                                  properties:
                                    data:
                                      description: Encrypted reasoning payload.
                                      type: string
                                    type:
                                      description: Block type.
                                      enum:
                                        - redacted_thinking
                                      type: string
                                  required:
                                    - type
                                    - data
                                  title: Redacted thinking
                                  type: object
                                - additionalProperties: true
                                  description: >-
                                    Any other block type, passed through to the
                                    provider.
                                  properties:
                                    type:
                                      description: Block type.
                                      type: string
                                  required:
                                    - type
                                  title: Provider block
                                  type: object
                            type: array
                        description: >-
                          Message content: a string, or an array of content
                          blocks.
                      role:
                        description: >-
                          Author of the message. Consecutive turns with the same
                          role are combined.
                        enum:
                          - user
                          - assistant
                        type: string
                    required:
                      - role
                      - content
                    type: object
                  type: array
                model:
                  description: Model whose tokenizer counts the request.
                  type: string
                output_config:
                  additionalProperties: true
                  description: Output shaping for the request.
                  type: object
                system:
                  anyOf:
                    - description: System prompt text.
                      type: string
                    - items:
                        properties:
                          cache_control:
                            description: >-
                              Prompt-cache marker. Placed on the last block
                              whose prefix should be cached.
                            properties:
                              ttl:
                                description: Cache lifetime. Defaults to 5m.
                                enum:
                                  - 5m
                                  - 1h
                                type: string
                              type:
                                description: Cache control type.
                                enum:
                                  - ephemeral
                                type: string
                            required:
                              - type
                            type: object
                          text:
                            description: System prompt text.
                            type: string
                          type:
                            description: Block type.
                            enum:
                              - text
                            type: string
                        required:
                          - type
                          - text
                        type: object
                      type: array
                  description: >-
                    System prompt: a string, or an array of text blocks that can
                    each carry cache_control.
                thinking:
                  description: Extended thinking configuration.
                  oneOf:
                    - properties:
                        budget_tokens:
                          description: >-
                            Tokens the model may spend thinking. Must be below
                            max_tokens.
                          type: integer
                        type:
                          description: Block type.
                          enum:
                            - enabled
                          type: string
                      required:
                        - type
                        - budget_tokens
                      title: Manual budget
                      type: object
                    - properties:
                        effort:
                          description: Reasoning effort.
                          enum:
                            - low
                            - medium
                            - high
                            - xhigh
                            - max
                          type: string
                        type:
                          description: Block type.
                          enum:
                            - adaptive
                          type: string
                      required:
                        - type
                      title: Adaptive
                      type: object
                    - properties:
                        type:
                          description: Block type.
                          enum:
                            - disabled
                          type: string
                      required:
                        - type
                      title: Disabled
                      type: object
                tool_choice:
                  description: Tool selection policy.
                  oneOf:
                    - properties:
                        type:
                          description: Block type.
                          enum:
                            - auto
                          type: string
                      required:
                        - type
                      title: Auto
                      type: object
                    - properties:
                        type:
                          description: Block type.
                          enum:
                            - any
                          type: string
                      required:
                        - type
                      title: Any
                      type: object
                    - properties:
                        type:
                          description: Block type.
                          enum:
                            - none
                          type: string
                      required:
                        - type
                      title: None
                      type: object
                    - properties:
                        name:
                          description: Name of the tool to call.
                          type: string
                        type:
                          description: Block type.
                          enum:
                            - tool
                          type: string
                      required:
                        - type
                        - name
                      title: Specific tool
                      type: object
                tools:
                  description: >-
                    Tools the model may call: custom tools with an input_schema,
                    or Anthropic server tools such as web_search.
                  items:
                    oneOf:
                      - description: A tool the caller executes.
                        properties:
                          cache_control:
                            description: >-
                              Prompt-cache marker. Placed on the last block
                              whose prefix should be cached.
                            properties:
                              ttl:
                                description: Cache lifetime. Defaults to 5m.
                                enum:
                                  - 5m
                                  - 1h
                                type: string
                              type:
                                description: Cache control type.
                                enum:
                                  - ephemeral
                                type: string
                            required:
                              - type
                            type: object
                          description:
                            description: What the tool does.
                            type: string
                          input_schema:
                            additionalProperties: true
                            description: JSON Schema describing the tool arguments.
                            properties:
                              properties:
                                additionalProperties: true
                                description: Argument schema by name.
                                type: object
                              required:
                                items:
                                  description: Required argument name.
                                  type: string
                                type: array
                              type:
                                description: Schema type, normally object.
                                type: string
                            type: object
                          name:
                            description: Tool name.
                            type: string
                        required:
                          - name
                          - input_schema
                        title: Custom tool
                        type: object
                      - additionalProperties: true
                        description: >-
                          A tool Anthropic runs, such as a web search.
                          Identified by its versioned type.
                        properties:
                          type:
                            description: >-
                              Versioned server tool type, for example
                              web_search_20250305.
                            type: string
                        required:
                          - type
                        title: Server tool
                        type: object
                  type: array
              required:
                - model
                - messages
              type: object
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                additionalProperties: false
                properties:
                  input_tokens:
                    description: Number of input tokens the request would consume.
                    format: int64
                    type: integer
                required:
                  - input_tokens
                type: object
          description: Token count for the request.
        '400':
          content:
            application/json:
              schema:
                additionalProperties: false
                properties:
                  error:
                    $ref: '#/components/schemas/PublicAnthropicErrorBody'
                    description: Error details.
                  type:
                    description: Envelope type.
                    enum:
                      - error
                    type: string
                required:
                  - type
                  - error
                type: object
          description: The request is malformed or uses a field the model rejects.
        '401':
          content:
            application/json:
              schema:
                additionalProperties: false
                properties:
                  error:
                    $ref: '#/components/schemas/PublicAnthropicErrorBody'
                    description: Error details.
                  type:
                    description: Envelope type.
                    enum:
                      - error
                    type: string
                required:
                  - type
                  - error
                type: object
          description: Missing or invalid API key.
components:
  schemas:
    PublicAnthropicCacheControl:
      additionalProperties: false
      properties:
        ttl:
          description: Cache lifetime. Defaults to 5m.
          enum:
            - 5m
            - 1h
          type: string
        type:
          description: Cache control type.
          enum:
            - ephemeral
          type: string
      required:
        - type
      type: object
    PublicAnthropicErrorBody:
      additionalProperties: false
      properties:
        message:
          description: Human-readable message.
          type: string
        type:
          description: >-
            Error category, for example invalid_request_error,
            authentication_error, not_found_error, rate_limit_error, or
            api_error.
          type: string
      required:
        - type
        - message
      type: object
  securitySchemes:
    ApiKey:
      type: http
      scheme: bearer
      bearerFormat: JWT

````

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