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

# Choose the provider for a new sandbox

> Orders the providers the team lists for one new sandbox with CostGraph AutoPilot. providers are ComputeSDK provider names in the team's order; a repeated name counts once. Send the sandbox size as size_class (xs, sm, md, lg, xl or 2xl), or as vcpus and memory_mib; size_class wins when both are sent. With no size and default_size true, each provider is priced at its own default size from its price list, and expected_seconds is the median of the team's sandboxes started at a default size; without either, the reason is no_size. policy (cheapest, balanced or fastest) orders this one sandbox by that policy instead of the team's, and is recorded with the decision; AutoPilot must still be on. Only the first 20 providers are priced, and a name CostGraph does not recognise is kept without a price. The team's first provider is the baseline. Providers are compared on expected_cost, the USD cost of one sandbox of the size running for expected_seconds: the run time rounded up to the provider's billing increment and at least its minimum billed time, at its price per hour. expected_seconds is the median run time, at most 24 hours, of the team's stopped sandboxes of the same size that started in the last 30 days when there are at least 20, otherwise 600. Each candidate carries two sets of start figures. benchmark_startup_p50_ms and benchmark_success_rate come from ComputeSDK's public burst benchmark (github.com/computesdk/benchmarks, MIT), which starts 100 sandboxes at once: the median milliseconds from a create request to the first command in that sandbox, and the share of the 100 starts that succeeded; both are null for a provider it does not benchmark. observed_startup_p50_ms is the median milliseconds from create_requested_at to the start of the team's own sandboxes of the same size on that provider that started in the last 30 days, null below 20 such starts; observed_success_rate is the share of the team's creates on that provider in the last 30 days that started, of starts plus failed events at any size, null below 20; observed_runs is that count of starts plus failures. Ranking uses the observed figure when there is one and the benchmark figure otherwise; startup_source says which start time decided (observed or benchmark, empty when neither is known), and the start time and success rate below mean those figures. When AutoPilot for sandboxes is on, the order follows the team's policy. cheapest: providers with a price for the size, lowest expected_cost first, then the others; a provider whose start time is more than twice the baseline's goes after the other priced providers, and a missing start time never holds a provider back. fastest: providers whose expected_cost is no more than the baseline's, fastest start first, then lower expected_cost, with those without a start time after them by expected_cost, then dearer providers in the same way, then those without a price; the baseline stays first unless a provider starts strictly faster than it. balanced: a provider whose expected_cost is no more than the baseline's and whose start time is within the baseline's start time plus the larger of 100 ms and 10% (the limit) scores (baseline expected_cost - its expected_cost) x (limit - its start time); providers scoring above zero come first, highest score first, then faster start, then lower expected_cost; then the other priced providers by start time (none last), then expected_cost; then those without a price; the baseline stays first when no provider scores above zero. In every policy a provider other than the baseline whose success rate is below 0.95 moves to the end, and remaining ties keep the team's order. reason is the policy (cheapest, fastest or balanced) when the first provider changed, otherwise no_better_candidate. The order stays the team's when AutoPilot is off (reason off), when no size is sent (reason no_size) and when the baseline has no price for the size (reason baseline_not_priced). candidates lists every provider in the returned order with its USD price per hour, expected_cost, billing_increment_seconds and minimum_billed_seconds for the size when known. Always answers 200 when the body has at least one provider: when CostGraph cannot choose (rate_limited, billing_required or error), the order is the team's, candidates is empty and decision_id is empty. When the reason is billing_required, billing_url links to the billing settings. Budgets set to enforce stop sandboxes while they are over for the period, as recorded by the daily budget evaluation: one with no filters stops every provider, and one filtered by provider drops those providers from the order; the recorded decision lists them with result budget_over and the budget's name in the sandbox list. When no listed provider is left, the reason is budget_exceeded, budget_name names the budget that stopped the first listed provider, order and candidates are empty, nothing is recorded, and no sandbox should be started. enforced_budget says whether any budget of the team is set to enforce, over or not, so a client knows not to start a sandbox when it cannot reach this endpoint; it is absent when CostGraph did not check (rate_limited, billing_required, or error before the check). Send decision_id back with the sandbox's started event.



## OpenAPI

````yaml /api-reference/costgraph/openapi.json post /api/v1/tenant/sandboxes/route
openapi: 3.0.0
info:
  description: Read and manage your CostGraph organization, spend, alerts, and settings.
  title: CostGraph API
  contact: {}
  version: '1.0'
servers:
  - url: https://api.costgraph.ai
security: []
tags:
  - name: ai
    x-group: AI
  - name: ai-serving
    x-group: AI serving
  - name: anomalies
    x-group: Anomalies
  - name: auth
    x-group: Auth
  - name: billing
    x-group: Billing
  - name: billing-export
    x-group: Billing export
  - name: budgets
    x-group: Budgets
  - name: ci
    x-group: CI
  - name: compute-recommendations
    x-group: Compute recommendations
  - name: config
    x-group: Config
  - name: context-graph
    x-group: Context graph
  - name: cost
    x-group: Cost
  - name: gpus
    x-group: GPUs
  - name: graphai
    x-group: Graph AI
  - name: integrations
    x-group: Integrations
  - name: invitations
    x-group: Invitations
  - name: kubernetes-clusters
    x-group: Kubernetes clusters
  - name: marketplace
    x-group: Marketplace
  - name: network
    x-group: Network
  - name: network-requests
    x-group: Network requests
  - name: notifications
    x-group: Notifications
  - name: oauth
    x-group: OAuth
  - name: oauth-clients
    x-group: OAuth clients
  - name: opencost
    x-group: OpenCost
  - name: operator
    x-group: Operator
  - name: organization
    x-group: Audit log
  - name: organizations
    x-group: Organizations
  - name: placement-alternatives
    x-group: Placement alternatives
  - name: reports
    x-group: Reports
  - name: sandboxes
    x-group: Sandboxes
  - name: settings
    x-group: Settings
  - name: sso
    x-group: Single sign-on
  - name: tenants
    x-group: Tenants
  - name: ticketing
    x-group: Ticketing
  - name: user
    x-group: Users
  - name: virtual-machines
    x-group: Virtual machines
  - name: virtual-tags
    x-group: Virtual tags
  - name: workflows
    x-group: Workflows
paths:
  /api/v1/tenant/sandboxes/route:
    post:
      tags:
        - sandboxes
      summary: Choose the provider for a new sandbox
      description: >-
        Orders the providers the team lists for one new sandbox with CostGraph
        AutoPilot. providers are ComputeSDK provider names in the team's order;
        a repeated name counts once. Send the sandbox size as size_class (xs,
        sm, md, lg, xl or 2xl), or as vcpus and memory_mib; size_class wins when
        both are sent. With no size and default_size true, each provider is
        priced at its own default size from its price list, and expected_seconds
        is the median of the team's sandboxes started at a default size; without
        either, the reason is no_size. policy (cheapest, balanced or fastest)
        orders this one sandbox by that policy instead of the team's, and is
        recorded with the decision; AutoPilot must still be on. Only the first
        20 providers are priced, and a name CostGraph does not recognise is kept
        without a price. The team's first provider is the baseline. Providers
        are compared on expected_cost, the USD cost of one sandbox of the size
        running for expected_seconds: the run time rounded up to the provider's
        billing increment and at least its minimum billed time, at its price per
        hour. expected_seconds is the median run time, at most 24 hours, of the
        team's stopped sandboxes of the same size that started in the last 30
        days when there are at least 20, otherwise 600. Each candidate carries
        two sets of start figures. benchmark_startup_p50_ms and
        benchmark_success_rate come from ComputeSDK's public burst benchmark
        (github.com/computesdk/benchmarks, MIT), which starts 100 sandboxes at
        once: the median milliseconds from a create request to the first command
        in that sandbox, and the share of the 100 starts that succeeded; both
        are null for a provider it does not benchmark. observed_startup_p50_ms
        is the median milliseconds from create_requested_at to the start of the
        team's own sandboxes of the same size on that provider that started in
        the last 30 days, null below 20 such starts; observed_success_rate is
        the share of the team's creates on that provider in the last 30 days
        that started, of starts plus failed events at any size, null below 20;
        observed_runs is that count of starts plus failures. Ranking uses the
        observed figure when there is one and the benchmark figure otherwise;
        startup_source says which start time decided (observed or benchmark,
        empty when neither is known), and the start time and success rate below
        mean those figures. When AutoPilot for sandboxes is on, the order
        follows the team's policy. cheapest: providers with a price for the
        size, lowest expected_cost first, then the others; a provider whose
        start time is more than twice the baseline's goes after the other priced
        providers, and a missing start time never holds a provider back.
        fastest: providers whose expected_cost is no more than the baseline's,
        fastest start first, then lower expected_cost, with those without a
        start time after them by expected_cost, then dearer providers in the
        same way, then those without a price; the baseline stays first unless a
        provider starts strictly faster than it. balanced: a provider whose
        expected_cost is no more than the baseline's and whose start time is
        within the baseline's start time plus the larger of 100 ms and 10% (the
        limit) scores (baseline expected_cost - its expected_cost) x (limit -
        its start time); providers scoring above zero come first, highest score
        first, then faster start, then lower expected_cost; then the other
        priced providers by start time (none last), then expected_cost; then
        those without a price; the baseline stays first when no provider scores
        above zero. In every policy a provider other than the baseline whose
        success rate is below 0.95 moves to the end, and remaining ties keep the
        team's order. reason is the policy (cheapest, fastest or balanced) when
        the first provider changed, otherwise no_better_candidate. The order
        stays the team's when AutoPilot is off (reason off), when no size is
        sent (reason no_size) and when the baseline has no price for the size
        (reason baseline_not_priced). candidates lists every provider in the
        returned order with its USD price per hour, expected_cost,
        billing_increment_seconds and minimum_billed_seconds for the size when
        known. Always answers 200 when the body has at least one provider: when
        CostGraph cannot choose (rate_limited, billing_required or error), the
        order is the team's, candidates is empty and decision_id is empty. When
        the reason is billing_required, billing_url links to the billing
        settings. Budgets set to enforce stop sandboxes while they are over for
        the period, as recorded by the daily budget evaluation: one with no
        filters stops every provider, and one filtered by provider drops those
        providers from the order; the recorded decision lists them with result
        budget_over and the budget's name in the sandbox list. When no listed
        provider is left, the reason is budget_exceeded, budget_name names the
        budget that stopped the first listed provider, order and candidates are
        empty, nothing is recorded, and no sandbox should be started.
        enforced_budget says whether any budget of the team is set to enforce,
        over or not, so a client knows not to start a sandbox when it cannot
        reach this endpoint; it is absent when CostGraph did not check
        (rate_limited, billing_required, or error before the check). Send
        decision_id back with the sandbox's started event.
      parameters:
        - description: Tenant ID
          name: X-CostGraph-Tenant-ID
          in: header
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/sandbox.RouteRequest'
        description: The team's providers and the sandbox size
        required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/responses.SuccessResponse'
                  - type: object
                    properties:
                      data:
                        $ref: '#/components/schemas/sandbox.RouteResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/responses.ErrorResponse'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/responses.ErrorResponse'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    sandbox.RouteRequest:
      type: object
      required:
        - providers
      properties:
        default_size:
          type: boolean
        memory_mib:
          type: integer
          example: 4096
        policy:
          type: string
          enum:
            - ''
            - cheapest
            - balanced
            - fastest
        providers:
          type: array
          minItems: 1
          items:
            type: string
          example:
            - e2b
            - daytona
        size_class:
          type: string
          enum:
            - ''
            - xs
            - sm
            - md
            - lg
            - xl
            - 2xl
          example: md
        vcpus:
          type: integer
          example: 2
    responses.SuccessResponse:
      type: object
      required:
        - message
        - status
      properties:
        data: {}
        message:
          type: string
          example: some message
        status:
          type: string
          example: success
    sandbox.RouteResponse:
      type: object
      required:
        - candidates
        - decision_id
        - order
        - provider
        - reason
      properties:
        billing_url:
          type: string
        budget_name:
          type: string
        candidates:
          type: array
          items:
            $ref: '#/components/schemas/sandbox.RouteCandidate'
        decision_id:
          type: string
        enforced_budget:
          type: boolean
          nullable: true
        expected_seconds:
          type: number
          nullable: true
        order:
          type: array
          items:
            type: string
        provider:
          type: string
        reason:
          type: string
          enum:
            - cheapest
            - balanced
            - fastest
            - no_better_candidate
            - 'off'
            - no_size
            - baseline_not_priced
            - budget_exceeded
            - rate_limited
            - billing_required
            - error
    responses.ErrorResponse:
      type: object
      required:
        - message
        - status
      properties:
        message:
          type: string
          example: some message
        status:
          type: string
          example: error
    sandbox.RouteCandidate:
      type: object
      required:
        - priced
        - provider
      properties:
        benchmark_startup_p50_ms:
          type: number
          nullable: true
        benchmark_success_rate:
          type: number
          nullable: true
        billing_increment_seconds:
          type: integer
          nullable: true
        expected_cost:
          type: number
          x-semantic: costAmount
          nullable: true
        minimum_billed_seconds:
          type: integer
          nullable: true
        observed_runs:
          type: integer
        observed_startup_p50_ms:
          type: number
          nullable: true
        observed_success_rate:
          type: number
          nullable: true
        price_per_hour:
          type: number
          x-semantic: costAmount
          nullable: true
        priced:
          type: boolean
        provider:
          type: string
        sku:
          type: string
        startup_source:
          type: string
          enum:
            - ''
            - observed
            - benchmark
  securitySchemes:
    ApiKeyAuth:
      description: API key for machine-to-machine authentication
      type: apiKey
      name: X-API-Key
      in: header

````

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