> ## Documentation Index
> Fetch the complete documentation index at: https://vastai-80aa3a82-auto-openapi-update-8483c1e9.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Route Serverless Request

> Ask the serverless router for a ready worker to handle one request against a serverless endpoint group. Returns the worker URL (plus a signature the worker validates) or a backlog/scaling status when no worker is immediately available.



## OpenAPI

````yaml /api-reference/openapi.yaml post /route/
openapi: 3.1.0
info:
  title: Vast.ai API
  description: >-
    Vast.ai REST API for managing GPU cloud instances, machine operations, and
    AI/ML workflows.


    ## AI Agent Quick-Start


    Install the CLI skill for your agent (Claude Code, Cursor, Windsurf, etc.):
      npx skills add vast-ai/vast-cli

    CLI reference:
    https://raw.githubusercontent.com/vast-ai/vast-cli/master/vastai/SKILL.md

    SDK reference:
    https://raw.githubusercontent.com/vast-ai/vast-cli/master/vastai_sdk/SKILL.md


    ## Auth

    All endpoints require `Authorization: Bearer $VAST_API_KEY`.

    Get your key at: https://cloud.vast.ai/manage-keys/


    ## Key Quirks

    - `gpu_ram` in CLI = GB; in REST API = MB (CLI auto-converts)

    - SSH keys must be registered BEFORE creating an instance (VM: no recovery;
    Docker: can add post-create)

    - `onstart` field is limited to 4048 characters -- gzip+base64 for longer
    scripts

    - `POST /api/v0/asks/{id}/` (create instance) returns `new_contract` as the
    instance ID, not `id`

    - Poll trap: if `actual_status` becomes `exited`, `unknown`, or `offline` it
    will never reach `running` -- destroy and retry
  version: 1.0.0
  contact:
    name: Vast.ai Support
    url: https://discord.gg/vast
servers:
  - url: https://console.vast.ai
    description: Production server
security:
  - BearerAuth: []
paths:
  /route/:
    post:
      tags:
        - Serverless
      summary: Route Serverless Request
      description: >-
        Ask the serverless router for a ready worker to handle one request
        against a serverless endpoint group. Returns the worker URL (plus a
        signature the worker validates) or a backlog/scaling status when no
        worker is immediately available.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                endpoint_id:
                  type: integer
                  description: Endpoint group id (supply this or `endpoint`).
                endpoint:
                  type: string
                  description: Endpoint group name (supply this or `endpoint_id`).
                api_key:
                  type: string
                  description: >-
                    Endpoint API key. May instead be supplied as a Bearer token
                    in the Authorization header.
                cost:
                  type: number
                  description: Estimated request cost in cost units (must be ≥ 0).
                latency:
                  type: number
                  description: >-
                    Average time a single worker takes to complete this request,
                    in seconds.
                request_idx:
                  type: integer
                  description: >-
                    Request index; 0 (or omitted) starts a new request, a prior
                    value re-polls it.
                guid:
                  type: integer
                  description: Client-supplied request identifier.
                replay_timeout:
                  type: number
                  description: >-
                    Seconds after which an unanswered request may be replayed on
                    another worker.
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  endpoint:
                    type: string
                  request_idx:
                    type: integer
                  url:
                    type: string
                    description: >-
                      Worker URL to send the request to (present when a worker
                      is ready).
                  cost:
                    type: number
                  reqnum:
                    type: integer
                  signature:
                    type: string
                    description: >-
                      Router signature the worker validates before serving the
                      request.
                  status:
                    type: string
                    description: >-
                      Set when no worker URL is returned (e.g. "endpoint
                      stopped").
        '400':
          description: >-
            Bad request — missing/invalid parameters (response body contains an
            `error_msg` string).
          content:
            application/json:
              schema:
                type: object
                properties:
                  error_msg:
                    type: string
      security:
        - BearerAuth: []
      servers:
        - url: https://run.vast.ai
          description: Serverless request router
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: API key must be provided in the Authorization header

````