openapi: 3.1.0
info:
  title: AgentSlot console API
  version: "1.0"
  description: |
    The API of the tenant dashboard (`app.agentslot.ai`). The dashboard and the API share one
    origin: the single-page application is served at `/`, the API below `/api`.

    Authentication uses either:
    - A browser session cookie (`asl_session`) set at sign-in, where state-changing requests must
      carry the session's CSRF token in `X-CSRF-Token` (`GET /api/v1/me` returns it), or
    - A Personal API Token (`Authorization: Bearer aslp_...`) minted via the console Settings page
      or `agentslot auth login` device authorization flow (CSRF header is not required for Bearer
      tokens; interactive browser-session endpoints such as CLI approval and logout require a cookie
      session).

    Requests from another origin are refused.

    Errors use one body shape (`Error`). `code` is stable and meant for programs; `message` is a
    human-readable English sentence that the dashboard may show as is.

    Upstream credentials are accepted only by the credential endpoints, are forwarded to the
    instance's isolated slot and are never returned or stored by the control plane.
servers:
  - url: https://app.agentslot.ai
security:
  - session: []
  - bearer: []

paths:
  /api/auth/{provider}/start:
    get:
      operationId: startSignIn
      summary: Redirect to the identity provider
      security: []
      parameters:
        - $ref: "#/components/parameters/Provider"
        - name: return_to
          in: query
          description: Path inside the dashboard to open after sign-in (default `/`).
          schema: { type: string }
      responses:
        "302": { description: Redirect to the provider's consent page }
        "404": { $ref: "#/components/responses/Error" }
  /api/auth/{provider}/callback:
    get:
      operationId: finishSignIn
      summary: Complete sign-in and set the session cookie
      description: |
        Creates the user on first sign-in, together with an account (tenant), a default route
        group and a default access point. Redirects to `return_to`, or to `/sign-in?error=<code>`
        when sign-in fails. The codes are `expired` (the sign-in took longer than 10 minutes or was
        started in another browser), `denied` (the user declined at the provider), `provider` (the
        provider could not be reached or rejected the exchange) and `email_unverified` (the
        provider account has no verified email).
      security: []
      parameters:
        - $ref: "#/components/parameters/Provider"
        - { name: code, in: query, schema: { type: string } }
        - { name: state, in: query, schema: { type: string } }
      responses:
        "302": { description: Redirect into the dashboard }
  /api/auth/providers:
    get:
      operationId: listSignInProviders
      summary: Sign-in providers and public client configuration enabled on this deployment
      security: []
      responses:
        "200":
          description: Providers
          content:
            application/json:
              schema:
                type: object
                required: [providers, email_enabled]
                properties:
                  providers:
                    type: array
                    items: { type: string, enum: [google, github, dev] }
                  email_enabled: { type: boolean }
                  turnstile_site_key: { type: string }
                  google_client_id: { type: string }
  /api/auth/email/send:
    post:
      operationId: sendEmailSignInCode
      summary: Send a one-time 6-digit verification code to an email address
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [email]
              properties:
                email: { type: string, format: email }
                turnstile_token: { type: string }
      responses:
        "200": { description: Verification code sent }
        "400": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Error" }
  /api/auth/email/verify:
    post:
      operationId: verifyEmailSignInCode
      summary: Verify a 6-digit email code and start a dashboard session
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [email, code]
              properties:
                email: { type: string, format: email }
                code: { type: string }
                return_to: { type: string }
      responses:
        "200": { description: Signed in }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
  /api/auth/google/onetap:
    post:
      operationId: googleOneTapSignIn
      summary: Verify a Google Identity Services ID token (One Tap) and start a dashboard session
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [credential]
              properties:
                credential: { type: string }
                return_to: { type: string }
      responses:
        "200": { description: Signed in }
        "401": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
  /api/auth/logout:
    post:
      operationId: signOut
      summary: End the session
      security:
        - session: []
      responses:
        "204": { description: Signed out }
  /api/auth/cli/start:
    post:
      operationId: startCLIAuth
      summary: Start a browser device-code authorization flow for agentslot CLI
      security: []
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                client_name: { type: string, example: "agentslot-cli (macbook)" }
      responses:
        "201":
          description: Authorization code issued
          content:
            application/json:
              schema: { $ref: "#/components/schemas/CLIAuthStart" }
        "429": { $ref: "#/components/responses/Error" }
  /api/auth/cli/poll:
    post:
      operationId: pollCLIAuth
      summary: Poll a CLI device authorization request and retrieve the issued Personal API Token once
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [device_code]
              properties:
                device_code: { type: string }
      responses:
        "200":
          description: Pending or approved (with one-time plaintext aslp_ token)
          content:
            application/json:
              schema: { $ref: "#/components/schemas/CLIAuthPoll" }
        "403": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "410": { $ref: "#/components/responses/Error" }
  /api/auth/cli/pending:
    get:
      operationId: getPendingCLIAuth
      summary: Inspect a pending CLI device authorization request by its 8-character user code
      security:
        - session: []
      parameters:
        - name: code
          in: query
          required: true
          schema: { type: string, example: "ABCD-EFGH" }
      responses:
        "200":
          description: Pending request metadata
          content:
            application/json:
              schema: { $ref: "#/components/schemas/CLIAuthPending" }
        "400": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
        "410": { $ref: "#/components/responses/Error" }
  /api/auth/cli/approve:
    post:
      operationId: approveCLIAuth
      summary: Approve a pending CLI device authorization request and mint a Personal API Token
      security:
        - session: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [user_code]
              properties:
                user_code: { type: string, example: "ABCD-EFGH" }
                name: { type: string, example: "MacBook Pro CLI" }
                expires_in_days: { type: [integer, "null"], minimum: 1, maximum: 365 }
      responses:
        "200":
          description: Approved
          content:
            application/json:
              schema:
                type: object
                required: [api_token]
                properties:
                  api_token: { $ref: "#/components/schemas/APIToken" }
        "400": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
        "410": { $ref: "#/components/responses/Error" }
  /api/auth/cli/deny:
    post:
      operationId: denyCLIAuth
      summary: Deny a pending CLI device authorization request
      security:
        - session: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [user_code]
              properties:
                user_code: { type: string, example: "ABCD-EFGH" }
      responses:
        "204": { description: Denied }
        "400": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }

  /api/v1/api-tokens:
    get:
      operationId: listAPITokens
      summary: List Personal API Tokens owned by the signed-in user in this workspace
      responses:
        "200":
          description: Personal API tokens
          content:
            application/json:
              schema:
                type: object
                required: [api_tokens]
                properties:
                  api_tokens:
                    type: array
                    items: { $ref: "#/components/schemas/APIToken" }
    post:
      operationId: createAPIToken
      summary: Mint a new Personal API Token (aslp_...) for CLI or automation
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name]
              properties:
                name: { type: string, minLength: 1, maxLength: 80 }
                expires_in_days: { type: [integer, "null"], minimum: 1, maximum: 365 }
      responses:
        "201":
          description: Created (plaintext token shown once)
          content:
            application/json:
              schema: { $ref: "#/components/schemas/APITokenWithSecret" }
        "400": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
  /api/v1/api-tokens/{token_id}:
    parameters:
      - $ref: "#/components/parameters/APITokenID"
    delete:
      operationId: revokeAPIToken
      summary: Revoke a Personal API Token immediately
      responses:
        "204": { description: Revoked }
        "404": { $ref: "#/components/responses/Error" }

  /api/v1/workspaces:
    get:
      operationId: listWorkspaces
      summary: List workspaces the signed-in user belongs to and pending invitations addressed to their email
      responses:
        "200":
          description: Workspaces and pending incoming invitations
          content:
            application/json:
              schema:
                type: object
                required: [current_tenant_id, workspaces, pending_invitations]
                properties:
                  current_tenant_id: { type: string }
                  workspaces:
                    type: array
                    items: { $ref: "#/components/schemas/WorkspaceSummary" }
                  pending_invitations:
                    type: array
                    items: { $ref: "#/components/schemas/IncomingInvitation" }
  /api/v1/workspaces/{tenant_id}/switch:
    parameters:
      - $ref: "#/components/parameters/TenantID"
    post:
      operationId: switchWorkspace
      summary: Switch the active browser session to another workspace the user belongs to
      security:
        - session: []
      responses:
        "200":
          description: Switched active workspace
          content:
            application/json:
              schema:
                type: object
                required: [tenant]
                properties:
                  tenant:
                    type: object
                    required: [id, name, role]
                    properties:
                      id: { type: string }
                      name: { type: string }
                      role: { type: string, enum: [owner, admin, member] }
        "403": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }

  /api/v1/workspace/members:
    get:
      operationId: listWorkspaceMembers
      summary: List members of the active workspace
      responses:
        "200":
          description: Workspace members
          content:
            application/json:
              schema:
                type: object
                required: [members]
                properties:
                  members:
                    type: array
                    items: { $ref: "#/components/schemas/WorkspaceMember" }
  /api/v1/workspace/members/{user_id}:
    parameters:
      - $ref: "#/components/parameters/UserID"
    patch:
      operationId: updateWorkspaceMember
      summary: Change a workspace member's role or transfer ownership (owner only)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [role]
              properties:
                role: { type: string, enum: [owner, admin, member] }
      responses:
        "200":
          description: Updated member
          content:
            application/json:
              schema: { $ref: "#/components/schemas/WorkspaceMember" }
        "400": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
    delete:
      operationId: removeWorkspaceMember
      summary: Remove a member from the workspace, or leave the workspace when user_id is the signed-in user
      responses:
        "204": { description: Removed }
        "403": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }

  /api/v1/workspace/invitations:
    get:
      operationId: listWorkspaceInvitations
      summary: List active pending invitations for the active workspace (owner or admin)
      responses:
        "200":
          description: Pending invitations
          content:
            application/json:
              schema:
                type: object
                required: [invitations]
                properties:
                  invitations:
                    type: array
                    items: { $ref: "#/components/schemas/WorkspaceInvitation" }
        "403": { $ref: "#/components/responses/Error" }
    post:
      operationId: createWorkspaceInvitation
      summary: Invite an email address to join the active workspace (owner or admin)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [email]
              properties:
                email: { type: string, format: email }
                role: { type: string, enum: [admin, member], default: member }
      responses:
        "201":
          description: Invitation created (invite_url returned once)
          content:
            application/json:
              schema:
                type: object
                required: [invitation, invite_url, email_sent]
                properties:
                  invitation: { $ref: "#/components/schemas/WorkspaceInvitation" }
                  invite_url: { type: string, format: uri }
                  email_sent: { type: boolean }
        "400": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
  /api/v1/workspace/invitations/{invitation_id}:
    parameters:
      - $ref: "#/components/parameters/InvitationID"
    delete:
      operationId: revokeWorkspaceInvitation
      summary: Revoke a pending workspace invitation (owner or admin)
      responses:
        "204": { description: Revoked }
        "403": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }

  /api/v1/invitations/lookup:
    get:
      operationId: lookupInvitation
      summary: Inspect non-sensitive metadata for an invitation token
      security: []
      parameters:
        - name: token
          in: query
          required: true
          schema: { type: string }
      responses:
        "200":
          description: Invitation details
          content:
            application/json:
              schema: { $ref: "#/components/schemas/InvitationLookup" }
        "400": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
  /api/v1/invitations/accept:
    post:
      operationId: acceptInvitation
      summary: Accept a pending invitation by token or invitation_id and switch into the workspace
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                token: { type: string }
                invitation_id: { type: string }
      responses:
        "200":
          description: Joined workspace
          content:
            application/json:
              schema:
                type: object
                required: [tenant]
                properties:
                  tenant:
                    type: object
                    required: [id, name, role]
                    properties:
                      id: { type: string }
                      name: { type: string }
                      role: { type: string, enum: [owner, admin, member] }
        "400": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
        "410": { $ref: "#/components/responses/Error" }
  /api/v1/invitations/{invitation_id}/decline:
    parameters:
      - $ref: "#/components/parameters/InvitationID"
    post:
      operationId: declineInvitation
      summary: Decline an incoming invitation addressed to the signed-in user's email
      responses:
        "204": { description: Declined }
        "404": { $ref: "#/components/responses/Error" }

  /api/v1/me:
    get:
      operationId: getMe
      summary: The signed-in user, the account and the CSRF token
      responses:
        "200":
          description: Session
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Me" }
        "401": { $ref: "#/components/responses/Error" }
    patch:
      operationId: updateMe
      summary: Update the signed-in user's display name or preset avatar
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                display_name: { type: string }
                avatar_url: { type: [string, "null"] }
      responses:
        "200": { description: Updated profile }
        "400": { $ref: "#/components/responses/Error" }
  /api/v1/me/avatar:
    put:
      operationId: uploadAvatar
      summary: Upload a custom WebP, PNG, or JPEG avatar (up to 128 KB)
      responses:
        "200": { description: Uploaded avatar URL and updated profile }
        "400": { $ref: "#/components/responses/Error" }
        "413": { $ref: "#/components/responses/Error" }
    delete:
      operationId: deleteAvatar
      summary: Remove the signed-in user's custom or preset avatar
      responses:
        "200": { description: Updated profile }
  /api/v1/users/{user_id}/avatar:
    get:
      operationId: getUserAvatar
      summary: Serve an uploaded user avatar image for the signed-in user or account member
      parameters:
        - { name: user_id, in: path, required: true, schema: { type: string } }
      responses:
        "200": { description: Avatar image bytes }
        "304": { description: Not modified }
        "404": { $ref: "#/components/responses/Error" }

  /api/v1/overview:
    get:
      operationId: getOverview
      summary: Seat usage, onboarding progress, instances needing attention and billing banners
      responses:
        "200":
          description: Overview
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Overview" }
  /api/v1/onboarding/config-copied:
    post:
      operationId: markConfigCopied
      summary: Record that the user copied a client configuration (onboarding step three)
      responses:
        "204": { description: Recorded }

  /api/v1/connectors:
    get:
      operationId: listConnectors
      summary: Connector types that can be chosen for a new instance
      responses:
        "200":
          description: Connector types
          content:
            application/json:
              schema:
                type: object
                required: [connectors]
                properties:
                  connectors:
                    type: array
                    items: { $ref: "#/components/schemas/Connector" }

  /api/v1/regions:
    get:
      operationId: listRegions
      summary: Sellable regions with real-time remaining stock and account seat counts
      responses:
        "200":
          description: Regions and account regional seats
          content:
            application/json:
              schema:
                type: object
                required: [regions, seats_by_region]
                properties:
                  regions:
                    type: array
                    items: { type: object }
                  seats_by_region:
                    type: array
                    items: { type: object }

  /api/v1/instances:
    get:
      operationId: listInstances
      summary: Instances of the account that are not destroyed
      responses:
        "200":
          description: Instances
          content:
            application/json:
              schema:
                type: object
                required: [instances]
                properties:
                  instances:
                    type: array
                    items: { $ref: "#/components/schemas/Instance" }
    post:
      operationId: createInstance
      summary: Create an instance
      description: |
        For cloud tiers (`pro` / `basic`), takes a regional cloud seat and starts the isolated
        slot; the instance is returned in `initializing` and reaches `awaiting_credentials`
        within about 30 seconds. A `basic` instance borrows a `pro` seat only when no `basic`
        seat is free in the chosen region and `confirm_borrow_pro` is true; otherwise the
        request fails with `borrow_confirmation_required` so the dashboard can ask first.

        For `bridge` (local bridge), allocates from the account's dynamic local bridge allowance
        (`base` free slots + `bonus_per_basic` per active Basic seat + `bonus_per_pro` per active
        Pro seat) and never consumes or borrows paid cloud seats. Returns `402 no_seat` when
        the bridge allowance is full.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/CreateInstanceRequest" }
      responses:
        "201":
          description: Created
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Instance" }
        "400": { $ref: "#/components/responses/Error" }
        "402":
          description: "`no_seat`: no seat of a usable tier is free"
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "403":
          description: "`connector_not_allowed`: the requested connector type is restricted to allowlisted test accounts"
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "409":
          description: "`borrow_confirmation_required`: the instance would take a pro seat"
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "503":
          description: "`no_capacity`: no host or egress is available right now"
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
  /api/v1/instances/{instance_id}:
    parameters:
      - $ref: "#/components/parameters/InstanceID"
    get:
      operationId: getInstance
      summary: Instance details, including its model catalog
      responses:
        "200":
          description: Instance
          content:
            application/json:
              schema: { $ref: "#/components/schemas/InstanceDetail" }
        "404": { $ref: "#/components/responses/Error" }
    patch:
      operationId: updateInstance
      summary: Rename an instance
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                alias:
                  type: [string, "null"]
                  description: Lowercase letters, digits and hyphens, 1–32 characters; usable as a model prefix.
      responses:
        "200":
          description: Updated
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Instance" }
        "409": { $ref: "#/components/responses/Error" }
    delete:
      operationId: deleteInstance
      summary: Delete an instance, or cancel its creation
      description: |
        Releases the seat at once; the slot and its encrypted credentials are erased in the
        background. When deleting a local bridge instance, any suspended local bridges that now
        fit within the account's dynamic bridge allowance are automatically resumed (oldest first)
        and routing is re-synced.
      responses:
        "204": { description: Deleting }
  /api/v1/instances/{instance_id}/rebuild:
    parameters:
      - $ref: "#/components/parameters/InstanceID"
    post:
      operationId: rebuildInstance
      summary: Recreate the instance's connector on the same host and egress, keeping its credentials
      description: |
        The connector container is replaced and unlocked again within seconds; the instance keeps
        its display state meanwhile, and `rebuild_available_at` is set. Allowed for running and
        awaiting-credential instances, once every 24 hours.
      responses:
        "202":
          description: Rebuilding
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Instance" }
        "409":
          description: "`not_rebuildable`: the instance is initializing, suspended or being deleted"
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429":
          description: "`rebuild_limited`: the last rebuild was less than 24 hours ago"
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
  /api/v1/instances/{instance_id}/providers:
    parameters:
      - $ref: "#/components/parameters/InstanceID"
    get:
      operationId: listInstanceProviders
      summary: Providers a managed instance can hold a credential for
      description: |
        The supported model vendors, relays, and subscription providers available inside the
        instance's slot. Pass the chosen id as `provider` when testing a key; `custom` (not listed)
        is an OpenAI-compatible endpoint at a base URL.
      responses:
        "200":
          description: The providers
          content:
            application/json:
              schema:
                type: object
                required: [providers]
                properties:
                  providers:
                    type: array
                    items: { $ref: "#/components/schemas/ProviderChoice" }
        "409":
          description: "`single_provider`: the instance's connector serves one provider; `not_ready`: the slot is not ready"
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
  /api/v1/instances/{instance_id}/credentials/test:
    parameters:
      - $ref: "#/components/parameters/InstanceID"
    post:
      operationId: testCredential
      summary: Test an API key inside the instance's slot
      description: |
        The key is handed to the slot, which lists the provider's models and sends a light probe
        through the instance's egress. The key is kept in the slot's memory, pending, until it is
        confirmed or `expires_at` passes; it is not returned by any endpoint.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/CredentialTestRequest" }
      responses:
        "200":
          description: The key works
          content:
            application/json:
              schema: { $ref: "#/components/schemas/CredentialTestResult" }
        "422":
          description: "`credential_rejected`, `upstream_unreachable` or `rate_limited`: the key could not be verified"
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "409": { $ref: "#/components/responses/Error" }
  /api/v1/instances/{instance_id}/credentials/confirm:
    parameters:
      - $ref: "#/components/parameters/InstanceID"
    post:
      operationId: confirmCredential
      summary: Store the tested key encrypted in the slot and start routing to the instance
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [test_id]
              properties:
                test_id: { type: string }
      responses:
        "200":
          description: Stored
          content:
            application/json:
              schema: { $ref: "#/components/schemas/InstanceDetail" }
        "410":
          description: "`test_expired`: the pending key was discarded; test again"
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
  /api/v1/instances/{instance_id}/signin/start:
    parameters:
      - $ref: "#/components/parameters/InstanceID"
    post:
      operationId: startSubscriptionSignIn
      summary: Start a subscription sign-in inside the instance's slot
      description: |
        Starts a subscription sign-in inside the slot runtime and mints a short-lived
        `agentslot-auth-browser` session bound to the slot's static egress. For Claude subscriptions
        on smaller slots, returns `202` while growing host memory and rebuilding the slot container.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [provider]
              properties:
                provider: { type: string, example: codex }
                site: { type: string, example: device }
                confirm_risk: { type: boolean }
      responses:
        "200":
          description: Sign-in started
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        "202":
          description: Resizing and rebuilding slot container for Claude
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        "400": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Error" }
  /api/v1/instances/{instance_id}/signin/{signin_id}:
    parameters:
      - $ref: "#/components/parameters/InstanceID"
      - name: signin_id
        in: path
        required: true
        schema: { type: string }
    get:
      operationId: getSubscriptionSignIn
      summary: Poll the status of a subscription sign-in; auto-confirms on completion
      responses:
        "200":
          description: Current sign-in status (and updated InstanceDetail when done)
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
  /api/v1/instances/{instance_id}/signin/{signin_id}/callback:
    parameters:
      - $ref: "#/components/parameters/InstanceID"
      - name: signin_id
        in: path
        required: true
        schema: { type: string }
    post:
      operationId: submitSubscriptionSignInCallback
      summary: Submit the OAuth callback URL to the instance's slot
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [url]
              properties:
                url: { type: string }
      responses:
        "200":
          description: Updated sign-in status
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
  /api/v1/instances/{instance_id}/signin/{signin_id}/cancel:
    parameters:
      - $ref: "#/components/parameters/InstanceID"
      - name: signin_id
        in: path
        required: true
        schema: { type: string }
    post:
      operationId: cancelSubscriptionSignIn
      summary: Cancel an in-flight subscription sign-in and close its auth browser session
      responses:
        "200":
          description: Canceled
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
  /api/v1/instances/{instance_id}/bridge/rotate:
    parameters:
      - $ref: "#/components/parameters/InstanceID"
    post:
      operationId: rotateBridgeToken
      summary: Issue a new bridge token and disconnect any active tunnel
      responses:
        "200":
          description: New bridge token (shown once)
          content:
            application/json:
              schema:
                type: object
                required: [token, token_prefix, command]
                properties:
                  token: { type: string }
                  token_prefix: { type: string }
                  command: { type: string }
        "404": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
  /api/v1/instances/{instance_id}/panel-session:
    parameters:
      - $ref: "#/components/parameters/InstanceID"
    post:
      operationId: createInstancePanelSession
      summary: Issue a short-lived signed handoff URL to open the tenant's unified VM2API management panel
      responses:
        "200":
          description: Signed handoff URL for the tenant VM2API relay panel subdomain (rly-<id>)
          content:
            application/json:
              schema:
                type: object
                required: [url, expires_in]
                properties:
                  url: { type: string, format: uri }
                  expires_in: { type: integer }
        "400": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Error" }
  /api/v1/bridge/connect:
    get:
      operationId: connectBridge
      summary: WebSocket tunnel endpoint for agentslot-bridge (authenticated by Bearer bridge token)
      security: []
      responses:
        "101":
          description: Switching Protocols (WebSocket)
        "401": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
  /api/v1/instances/{instance_id}/auth-browser/sessions:
    parameters:
      - $ref: "#/components/parameters/InstanceID"
    post:
      operationId: createAuthBrowserSession
      summary: Mint a short-lived agentslot-auth-browser session bound to this slot's static egress
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                start_url: { type: string, format: uri }
      responses:
        "201":
          description: Auth browser session created
          content:
            application/json:
              schema: { $ref: "#/components/schemas/AuthBrowserSession" }
  /api/v1/instances/{instance_id}/authorizations:
    parameters:
      - $ref: "#/components/parameters/InstanceID"
    post:
      operationId: startAuthorization
      summary: Start an OAuth authorization for a connector that supports it
      description: |
        Returns the provider's authorization page. The session is single-use and valid for
        15 minutes; after the provider redirects back, the obtained key is stored in the slot and
        the browser lands on `/instances/{instance_id}?authorization=success` (or `=failed`).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [provider]
              properties:
                provider: { type: string, enum: [openrouter] }
      responses:
        "201":
          description: Started
          content:
            application/json:
              schema:
                type: object
                required: [authorize_url, expires_at]
                properties:
                  authorize_url: { type: string, format: uri }
                  expires_at: { type: string, format: date-time }
  /api/oauth/{provider}/callback:
    get:
      operationId: finishAuthorization
      summary: Provider redirect target of a connector authorization
      parameters:
        - name: provider
          in: path
          required: true
          schema: { type: string, enum: [openrouter] }
        - { name: session, in: query, required: true, schema: { type: string } }
        - { name: code, in: query, schema: { type: string } }
      responses:
        "302": { description: Redirect to the instance page }
  /api/v1/instances/{instance_id}/usage:
    parameters:
      - $ref: "#/components/parameters/InstanceID"
      - $ref: "#/components/parameters/Window"
    get:
      operationId: getInstanceUsage
      summary: Request metrics of the instance
      responses:
        "200":
          description: Usage
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Usage" }

  /api/v1/route-groups:
    get:
      operationId: listRouteGroups
      summary: Route groups with their members
      responses:
        "200":
          description: Route groups
          content:
            application/json:
              schema:
                type: object
                required: [route_groups]
                properties:
                  route_groups:
                    type: array
                    items: { $ref: "#/components/schemas/RouteGroup" }
    post:
      operationId: createRouteGroup
      summary: Create a route group
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/RouteGroupInput" }
      responses:
        "201":
          description: Created
          content:
            application/json:
              schema: { $ref: "#/components/schemas/RouteGroup" }
        "409": { $ref: "#/components/responses/Error" }
  /api/v1/route-groups/{route_group_id}:
    parameters:
      - $ref: "#/components/parameters/RouteGroupID"
    put:
      operationId: updateRouteGroup
      summary: Replace a route group's name, strategy and members
      description: Members are listed in priority order; for the priority strategy the first member is tried first.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/RouteGroupInput" }
      responses:
        "200":
          description: Updated
          content:
            application/json:
              schema: { $ref: "#/components/schemas/RouteGroup" }
        "409": { $ref: "#/components/responses/Error" }
    delete:
      operationId: deleteRouteGroup
      summary: Delete a route group; its instances are kept
      description: Access points that used the group as their default are left without a default route group.
      responses:
        "204": { description: Deleted }

  /api/v1/access-points:
    get:
      operationId: listAccessPoints
      summary: Access points, including revoked ones
      responses:
        "200":
          description: Access points
          content:
            application/json:
              schema:
                type: object
                required: [access_points]
                properties:
                  access_points:
                    type: array
                    items: { $ref: "#/components/schemas/AccessPoint" }
    post:
      operationId: createAccessPoint
      summary: Create an access point; its token is returned only in this response
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/AccessPointInput" }
      responses:
        "201":
          description: Created
          content:
            application/json:
              schema: { $ref: "#/components/schemas/AccessPointWithToken" }
  /api/v1/access-points/{access_point_id}:
    parameters:
      - $ref: "#/components/parameters/AccessPointID"
    patch:
      operationId: updateAccessPoint
      summary: Change an access point's name, default route group or concurrency limit
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/AccessPointInput" }
      responses:
        "200":
          description: Updated
          content:
            application/json:
              schema: { $ref: "#/components/schemas/AccessPoint" }
    delete:
      operationId: revokeAccessPoint
      summary: Revoke an access point; the gateway rejects its token within seconds
      responses:
        "204": { description: Revoked }
  /api/v1/access-points/{access_point_id}/reveal:
    parameters:
      - $ref: "#/components/parameters/AccessPointID"
    post:
      operationId: revealAccessPointToken
      summary: Show the token of the automatically created default access point, once
      description: Fails with `token_not_revealable` once the token has been shown; rotate the token instead.
      responses:
        "200":
          description: Token
          content:
            application/json:
              schema: { $ref: "#/components/schemas/AccessPointWithToken" }
        "410": { $ref: "#/components/responses/Error" }
  /api/v1/access-points/{access_point_id}/rotate:
    parameters:
      - $ref: "#/components/parameters/AccessPointID"
    post:
      operationId: rotateAccessPointToken
      summary: Replace the token; the previous token stops working at once
      responses:
        "200":
          description: New token
          content:
            application/json:
              schema: { $ref: "#/components/schemas/AccessPointWithToken" }
  /api/v1/access-points/{access_point_id}/usage:
    parameters:
      - $ref: "#/components/parameters/AccessPointID"
      - $ref: "#/components/parameters/Window"
    get:
      operationId: getAccessPointUsage
      summary: Request metrics of the access point
      responses:
        "200":
          description: Usage
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Usage" }

  /api/v1/billing:
    get:
      operationId: getBilling
      summary: Seats, subscription batches, payments and the instances that the next expiry would remove
      responses:
        "200":
          description: Billing
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Billing" }
  /api/v1/checkouts:
    post:
      operationId: createCheckout
      summary: Start a checkout for new seats
      description: |
        Every purchase becomes its own subscription batch. Seats are added once the payment is
        confirmed.

        `card` (the default) opens a subscription checkout that the payment provider renews every
        month; it returns to `/billing?checkout=success`. `crypto` opens a stablecoin invoice for a
        prepaid term of `months` (one of `payment_methods[].months` in `GET /api/v1/billing`),
        priced at the monthly seat price times seats times months; it returns to
        `/billing?checkout=crypto`. Prepaid batches are renewed with
        `POST /api/v1/batches/{batch_id}/renewals`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [tier, units]
              properties:
                tier: { $ref: "#/components/schemas/SeatTier" }
                region: { type: string, description: Seat region code; the default region when omitted. }
                units: { type: integer, minimum: 1, maximum: 100 }
                method: { $ref: "#/components/schemas/PaymentMethodKind" }
                months: { type: integer, minimum: 1, description: Prepaid term; required with `crypto`. }
      responses:
        "201":
          description: Checkout created
          content:
            application/json:
              schema:
                type: object
                required: [checkout_url]
                properties:
                  checkout_url: { type: string, format: uri }
        "400": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Error" }
  /api/v1/batches/{batch_id}/renewals:
    post:
      operationId: renewBatch
      summary: Start a stablecoin checkout that extends a prepaid batch
      description: |
        The batch keeps its seats, tier and region. When the payment is confirmed the batch is
        active again: an active or past-due batch continues from its current period end, a
        suspended batch starts a new period at the payment time. Expired batches cannot be
        renewed. Returns to `/billing?checkout=crypto`.
      parameters:
        - { name: batch_id, in: path, required: true, schema: { type: string } }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [months]
              properties:
                months: { type: integer, minimum: 1, description: "One of `payment_methods[].months` of the crypto method." }
      responses:
        "201":
          description: Checkout created
          content:
            application/json:
              schema:
                type: object
                required: [checkout_url]
                properties:
                  checkout_url: { type: string, format: uri }
        "400": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Error" }
  /api/v1/billing/portal:
    post:
      operationId: openBillingPortal
      summary: Link to the payment provider's customer portal (update card, cancel renewal, invoices) of the latest card subscription
      responses:
        "200":
          description: Portal link
          content:
            application/json:
              schema:
                type: object
                required: [url]
                properties:
                  url: { type: string, format: uri }
        "404": { $ref: "#/components/responses/Error" }

  /api/v1/usage:
    get:
      operationId: getUsage
      summary: Request metrics of the account
      parameters:
        - $ref: "#/components/parameters/Window"
      responses:
        "200":
          description: Usage
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Usage" }

  /api/v1/notifications:
    get:
      operationId: listNotifications
      summary: The 50 most recent notifications
      responses:
        "200":
          description: Notifications
          content:
            application/json:
              schema:
                type: object
                required: [notifications, unread]
                properties:
                  unread: { type: integer }
                  notifications:
                    type: array
                    items: { $ref: "#/components/schemas/Notification" }
  /api/v1/notifications/read:
    post:
      operationId: markNotificationsRead
      summary: Mark all notifications as read
      responses:
        "204": { description: Marked }
  /api/v1/settings:
    get:
      operationId: getSettings
      summary: Account settings
      responses:
        "200":
          description: Settings
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Settings" }
    put:
      operationId: updateSettings
      summary: Change account settings
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/SettingsUpdate" }
      responses:
        "200":
          description: Updated
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Settings" }

  /api/v1/events:
    get:
      operationId: streamEvents
      summary: Server-sent events for live updates
      description: |
        A `text/event-stream`. Each `instance` event carries an `Instance` whenever an
        instance's display state, egress or credential changes; when an instance has been
        deleted, a last `instance` event carries only its `id` and `display_state: destroying`,
        after which it no longer appears. Each `notification` event carries a `Notification`.
        A comment line is sent every 15 seconds to keep the stream open; the server ends the
        stream after an hour and the browser reconnects.
      responses:
        "200":
          description: Event stream
          content:
            text/event-stream:
              schema: { type: string }

  /api/v1/auth-browser/session:
    get:
      operationId: getAuthBrowserSession
      summary: Read auth browser session metadata and live sign-in status (Bearer aslab_ token)
      security: []
      responses:
        "200":
          description: Session details
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        "401": { $ref: "#/components/responses/Error" }
  /api/v1/auth-browser/callback:
    post:
      operationId: submitAuthBrowserCallback
      summary: Submit captured OAuth callback URL from local agentslot-auth-browser (Bearer aslab_ token)
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [url]
              properties:
                url: { type: string }
      responses:
        "200":
          description: Callback submitted
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        "401": { $ref: "#/components/responses/Error" }
  /api/v1/auth-browser/close:
    post:
      operationId: closeAuthBrowserSession
      summary: Revoke an auth browser session and close its active tunnels (Bearer aslab_ token)
      security: []
      responses:
        "204": { description: Closed }
        "401": { $ref: "#/components/responses/Error" }
  /api/v1/auth-browser/tunnel:
    get:
      operationId: openAuthBrowserTunnel
      summary: Open a WebSocket binary tunnel through the session instance's static egress (Bearer aslab_ token)
      security: []
      parameters:
        - name: target
          in: query
          required: true
          schema: { type: string }
      responses:
        "101": { description: Switching Protocols (WebSocket binary stream) }
        "401": { $ref: "#/components/responses/Error" }

components:
  securitySchemes:
    session:
      type: apiKey
      in: cookie
      name: asl_session
    bearer:
      type: http
      scheme: bearer
      bearerFormat: aslp_token
      description: Personal API Token starting with `aslp_`, created in Console Settings or via `agentslot auth login`.

  parameters:
    APITokenID:
      name: token_id
      in: path
      required: true
      schema: { type: string, pattern: "^pat_[a-z2-7]{26}$" }
    TenantID:
      name: tenant_id
      in: path
      required: true
      schema: { type: string, pattern: "^ten_[a-z2-7]{26}$" }
    UserID:
      name: user_id
      in: path
      required: true
      schema: { type: string, pattern: "^usr_[a-z2-7]{26}$" }
    InvitationID:
      name: invitation_id
      in: path
      required: true
      schema: { type: string, pattern: "^inv_[a-z2-7]{26}$" }
    Provider:
      name: provider
      in: path
      required: true
      schema: { type: string, enum: [google, github, dev] }
    InstanceID:
      name: instance_id
      in: path
      required: true
      schema: { type: string, pattern: "^ins_[a-z2-7]{26}$" }
    RouteGroupID:
      name: route_group_id
      in: path
      required: true
      schema: { type: string }
    AccessPointID:
      name: access_point_id
      in: path
      required: true
      schema: { type: string }
    Window:
      name: window
      in: query
      schema: { type: string, enum: [1h, 24h, 7d], default: 24h }

  responses:
    Error:
      description: Error
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }

  schemas:
    Error:
      type: object
      required: [error]
      properties:
        error:
          type: object
          required: [code, message]
          properties:
            code: { type: string }
            message: { type: string }

    SeatTier:
      type: string
      enum: [pro, basic]
    InstanceTier:
      type: string
      enum: [pro, basic, bridge]
    SeatType:
      type: string
      enum: [pro, basic, free_bridge]
    DisplayState:
      type: string
      description: |
        The state shown to the tenant: `initializing`, `awaiting_credentials`, `ready`,
        `cooling_down` (upstream rate limit or balance; see `retry_after`),
        `credentials_outdated` (the provider rejected the key), `network_error` (a platform-side
        fault, alerted automatically), `suspended_overdue` (payment overdue or local bridge
        allowance exceeded) and `destroying`.
      enum: [initializing, awaiting_credentials, ready, cooling_down, credentials_outdated, network_error, suspended_overdue, destroying]

    Me:
      type: object
      required: [user, tenant, csrf_token, gateway_url]
      properties:
        user:
          type: object
          required: [id, email, display_name]
          properties:
            id: { type: string }
            email: { type: string }
            display_name: { type: string }
            avatar_url: { type: [string, "null"] }
            providers:
              type: array
              items: { type: string, enum: [google, github, email, dev] }
        tenant:
          type: object
          required: [id, name, role]
          properties:
            id: { type: string }
            name: { type: string }
            role: { type: string, enum: [owner, admin, member] }
        csrf_token: { type: string }
        gateway_url:
          type: string
          description: Base URL clients use, e.g. `https://api.agentslot.dev`.

    APIToken:
      type: object
      required: [id, name, token_prefix, created_at]
      properties:
        id: { type: string, pattern: "^pat_[a-z2-7]{26}$" }
        name: { type: string }
        token_prefix: { type: string, example: "aslp_abcdefg" }
        created_at: { type: string, format: date-time }
        last_used_at: { type: [string, "null"], format: date-time }
        expires_at: { type: [string, "null"], format: date-time }
        revoked_at: { type: [string, "null"], format: date-time }
    APITokenWithSecret:
      type: object
      required: [api_token, token]
      properties:
        api_token: { $ref: "#/components/schemas/APIToken" }
        token: { type: string, description: "Plaintext `aslp_` token, returned once." }
    WorkspaceSummary:
      type: object
      required: [id, name, role, member_count, created_at]
      properties:
        id: { type: string, pattern: "^ten_[a-z2-7]{26}$" }
        name: { type: string }
        role: { type: string, enum: [owner, admin, member] }
        member_count: { type: integer }
        created_at: { type: string, format: date-time }
    IncomingInvitation:
      type: object
      required: [id, tenant_id, tenant_name, role, invited_by_name, invited_by_email, created_at, expires_at]
      properties:
        id: { type: string, pattern: "^inv_[a-z2-7]{26}$" }
        tenant_id: { type: string, pattern: "^ten_[a-z2-7]{26}$" }
        tenant_name: { type: string }
        role: { type: string, enum: [admin, member] }
        invited_by_name: { type: string }
        invited_by_email: { type: string }
        created_at: { type: string, format: date-time }
        expires_at: { type: string, format: date-time }
    WorkspaceMember:
      type: object
      required: [user_id, email, display_name, role, joined_at, is_self]
      properties:
        user_id: { type: string, pattern: "^usr_[a-z2-7]{26}$" }
        email: { type: string }
        display_name: { type: string }
        avatar_url: { type: [string, "null"] }
        role: { type: string, enum: [owner, admin, member] }
        joined_at: { type: string, format: date-time }
        is_self: { type: boolean }
    WorkspaceInvitation:
      type: object
      required: [id, email, role, invited_by_id, invited_by_name, invited_by_email, created_at, expires_at]
      properties:
        id: { type: string, pattern: "^inv_[a-z2-7]{26}$" }
        email: { type: string }
        role: { type: string, enum: [admin, member] }
        invited_by_id: { type: string }
        invited_by_name: { type: string }
        invited_by_email: { type: string }
        created_at: { type: string, format: date-time }
        expires_at: { type: string, format: date-time }
    InvitationLookup:
      type: object
      required: [status, tenant_name, role, invited_by_name, email_hint, expires_at, signed_in]
      properties:
        status: { type: string, enum: [pending, accepted, revoked, expired] }
        tenant_name: { type: string }
        role: { type: string, enum: [admin, member] }
        invited_by_name: { type: string }
        email_hint: { type: string }
        expires_at: { type: string, format: date-time }
        signed_in: { type: boolean }
        signed_in_email: { type: string }
        email_matches: { type: boolean }
    CLIAuthStart:
      type: object
      required: [device_code, user_code, verification_url, verification_url_complete, expires_in, interval]
      properties:
        device_code: { type: string }
        user_code: { type: string, example: "ABCD-EFGH" }
        verification_url: { type: string, format: uri }
        verification_url_complete: { type: string, format: uri }
        expires_in: { type: integer }
        interval: { type: integer }
    CLIAuthPending:
      type: object
      required: [user_code, client_name, expires_at]
      properties:
        user_code: { type: string, example: "ABCD-EFGH" }
        client_name: { type: string }
        expires_at: { type: string, format: date-time }
    CLIAuthPoll:
      type: object
      required: [status]
      properties:
        status: { type: string, enum: [pending, approved] }
        interval: { type: integer }
        token: { type: string }
        token_prefix: { type: string }
        api_token: { $ref: "#/components/schemas/APIToken" }
        user: { type: object, additionalProperties: true }
        tenant: { type: object, additionalProperties: true }
        gateway_url: { type: string }

    SeatCount:
      type: object
      required: [quota, used]
      properties:
        quota: { type: integer }
        used: { type: integer }
    BridgeSeatCount:
      type: object
      description: |
        Dynamic local bridge allowance (`quota = base + bonus`, where `bonus = live_basic *
        bonus_per_basic + live_pro * bonus_per_pro`). Local bridges never consume paid cloud seats.
      required: [quota, used, base, bonus, bonus_per_pro, bonus_per_basic]
      properties:
        quota: { type: integer }
        used: { type: integer }
        base: { type: integer, description: Default free local bridge slots per account (5). }
        bonus: { type: integer, description: Extra local bridge slots granted by live paid cloud seats. }
        bonus_per_pro: { type: integer, description: Bonus local bridge slots per live Pro seat (5). }
        bonus_per_basic: { type: integer, description: Bonus local bridge slots per live Basic seat (2). }
    Seats:
      type: object
      required: [pro, basic, free_bridge]
      properties:
        pro: { $ref: "#/components/schemas/SeatCount" }
        basic: { $ref: "#/components/schemas/SeatCount" }
        free_bridge: { $ref: "#/components/schemas/BridgeSeatCount" }

    Overview:
      type: object
      required: [seats, onboarding, attention, banners]
      properties:
        seats: { $ref: "#/components/schemas/Seats" }
        onboarding:
          type: object
          description: Each step is judged from the account's data.
          required: [seats_purchased, instance_ready, config_copied, first_call, completed]
          properties:
            seats_purchased: { type: boolean }
            instance_ready: { type: boolean }
            config_copied: { type: boolean }
            first_call: { type: boolean }
            completed: { type: boolean }
        attention:
          type: array
          description: Instances whose state needs the tenant (credentials_outdated, suspended_overdue) or explains an outage (network_error, cooling_down).
          items: { $ref: "#/components/schemas/Instance" }
        banners:
          type: array
          items: { $ref: "#/components/schemas/Banner" }
    Banner:
      type: object
      required: [kind, batch_id, tier, deadline]
      properties:
        kind:
          type: string
          enum: [payment_failed, suspended, expiring]
          description: |
            `payment_failed`: renewal failed or the prepaid period ended, forwarding continues until `deadline`;
            `suspended`: instances are suspended, they are deleted at `deadline`;
            `expiring`: renewal is canceled, or the complimentary or prepaid period ends at `deadline`.
        batch_id: { type: string }
        renewal: { $ref: "#/components/schemas/Renewal" }
        tier: { $ref: "#/components/schemas/SeatTier" }
        deadline: { type: string, format: date-time }
        instances:
          type: array
          description: Identifiers of the instances that are removed at the deadline unless seats are added.
          items: { type: string }

    Connector:
      type: object
      required: [type, label, authorization, base_url]
      properties:
        type: { type: string, example: openai }
        label: { type: string, example: OpenAI }
        authorization:
          type: string
          enum: [api_key, oauth]
          description: "`oauth`: the key is obtained through `POST /instances/{id}/authorizations`."
        oauth_provider: { type: [string, "null"], example: openrouter }
        base_url:
          type: string
          enum: [none, optional, required]
          description: Whether the credential form shows a base URL field.
        default_base_url: { type: [string, "null"] }
        key_hint: { type: [string, "null"], description: Where the tenant finds the key, e.g. the provider's console page. }
        offered:
          type: boolean
          description: |
            New instances can use this connector type. Once the `managed` connector runtime is
            available it is the default offered connector; allowlisted test runtimes (such as
            `vm2api`) are additionally offered for authorized tenants, and legacy types stay listed
            for existing instances.
        multi_provider:
          type: boolean
          description: Whether instances of this connector choose their provider or subscription inside the slot after creation.
        experimental:
          type: boolean
          description: Whether this connector is an allowlist-gated test runtime (such as `vm2api`).

    ProviderChoice:
      type: object
      required: [id, label, group, authorization]
      properties:
        id: { type: string, example: deepseek, description: The provider's preset or subscription id. }
        label: { type: string, example: DeepSeek }
        group:
          type: string
          enum: [vendor, relay, subscription]
          description: "`vendor`: a model vendor's own API; `relay`: one key for models of many vendors; `subscription`: a user-owned subscription account."
        authorization:
          type: string
          enum: [api_key, oauth, subscription]
          description: "`oauth`: the key can be obtained through `POST /instances/{id}/authorizations`; `subscription`: signed in through `/instances/{id}/signin/start`."
        risk_note:
          type: string
          description: Risk warning shown before starting sign-in when present.

    AuthBrowserSession:
      type: object
      required: [token, expires_at, command]
      properties:
        token: { type: string }
        expires_at: { type: string, format: date-time }
        expected_egress: { type: string }
        region: { type: string }
        command: { type: string }

    Egress:
      type: object
      required: [region, address]
      properties:
        region: { type: string, example: us-nyc }
        region_label: { type: string }
        address: { type: string, description: Public address upstream providers see. }
        ip_type:
          type: string
          enum: [residential, isp, datacenter, unknown]
        geo_country: { type: [string, "null"] }
        geo_subdivision: { type: [string, "null"] }
        geo_city: { type: [string, "null"] }
        geo_isp: { type: [string, "null"] }

    Bridge:
      type: object
      required: [connected, token_prefix]
      properties:
        connected: { type: boolean }
        token_prefix: { type: string }
        connected_at: { type: [string, "null"], format: date-time }
        last_seen_at: { type: [string, "null"], format: date-time }
        client_info: { type: [string, "null"] }
        token: { type: string }
        command: { type: string }

    Instance:
      type: object
      required: [id, tier, seat_type, borrowed_pro, connector_type, display_state, created_at]
      properties:
        id: { type: string }
        alias: { type: [string, "null"] }
        tier: { $ref: "#/components/schemas/InstanceTier" }
        region: { type: string }
        region_label: { type: string }
        seat_type: { $ref: "#/components/schemas/SeatType" }
        borrowed_pro: { type: boolean }
        connector_type: { type: string }
        provider:
          type: [string, "null"]
          description: For a managed instance with a saved credential, the provider id, or `custom`.
        provider_label:
          type: string
          description: The instance's provider by name; empty for a managed instance without credentials.
        credential_kind:
          type: string
          enum: [api_key, subscription]
        display_state: { $ref: "#/components/schemas/DisplayState" }
        retry_after:
          type: [string, "null"]
          format: date-time
          description: When a cooling-down instance is probed again.
        egress:
          oneOf:
            - $ref: "#/components/schemas/Egress"
            - type: "null"
        bridge:
          $ref: "#/components/schemas/Bridge"
        credential_fingerprint:
          type: [string, "null"]
          description: The last characters and a digest prefix of the stored key; never the key.
        model_count: { type: integer }
        created_at: { type: string, format: date-time }
        last_used_at: { type: [string, "null"], format: date-time }
        rebuild_available_at:
          type: [string, "null"]
          format: date-time
          description: When the next rebuild is allowed; null when allowed now.
    InstanceDetail:
      allOf:
        - $ref: "#/components/schemas/Instance"
        - type: object
          required: [models, route_groups]
          properties:
            models:
              type: array
              items:
                type: object
                required: [id]
                properties:
                  id: { type: string }
                  capabilities: { type: array, items: { type: string } }
                  context_window: { type: integer }
            route_groups:
              type: array
              items:
                type: object
                required: [id, name]
                properties:
                  id: { type: string }
                  name: { type: string }
    CreateInstanceRequest:
      type: object
      required: [tier]
      properties:
        tier: { $ref: "#/components/schemas/InstanceTier" }
        region: { type: string, description: "Required for cloud tiers (`pro`, `basic`); ignored for `bridge`." }
        connector_type: { type: string, description: "Optional for `bridge` (defaults to `managed`)." }
        alias: { type: [string, "null"] }
        confirm_borrow_pro:
          type: boolean
          description: The tenant accepted that a `basic` cloud instance takes a free `pro` seat (unused for `bridge`).
    CredentialTestRequest:
      type: object
      required: [secret]
      properties:
        secret: { type: string, description: The provider API key. }
        base_url: { type: [string, "null"], format: uri }
        provider:
          type: string
          description: |
            For a managed instance: the provider the key belongs to, an id from
            `GET /instances/{id}/providers` or `custom` (which needs `base_url`). Defaults to the
            instance's current provider.
    CredentialTestResult:
      type: object
      required: [test_id, fingerprint, models, probe_latency_ms, expires_at]
      properties:
        test_id: { type: string }
        fingerprint: { type: string }
        models:
          type: array
          items:
            type: object
            required: [id]
            properties:
              id: { type: string }
              capabilities: { type: array, items: { type: string } }
        probe_latency_ms: { type: integer }
        expires_at: { type: string, format: date-time }

    RouteGroupInput:
      type: object
      required: [name, strategy]
      properties:
        name: { type: string, description: "Lowercase letters, digits and hyphens; usable as a model prefix (`name/model`)." }
        strategy: { type: string, enum: [priority, weighted_affinity] }
        members:
          type: array
          description: In priority order. Omitted on create means no members.
          items:
            type: object
            required: [instance_id]
            properties:
              instance_id: { type: string }
              weight: { type: integer, minimum: 1, maximum: 1000, default: 100 }
    RouteGroup:
      type: object
      required: [id, name, strategy, members, created_at]
      properties:
        id: { type: string }
        name: { type: string }
        strategy: { type: string, enum: [priority, weighted_affinity] }
        members:
          type: array
          items:
            type: object
            required: [instance_id, connector_type, display_state, weight]
            properties:
              instance_id: { type: string }
              alias: { type: [string, "null"] }
              connector_type: { type: string }
              provider_label: { type: string, description: The instance's provider by name. }
              display_state: { $ref: "#/components/schemas/DisplayState" }
              weight: { type: integer }
        created_at: { type: string, format: date-time }

    AccessPointInput:
      type: object
      required: [name]
      properties:
        name: { type: string }
        default_route_group_id: { type: [string, "null"] }
        max_concurrency: { type: [integer, "null"], minimum: 1 }
    AccessPoint:
      type: object
      required: [id, name, token_prefix, created_at, token_revealable]
      properties:
        id: { type: string }
        name: { type: string }
        token_prefix: { type: string, description: The first characters of the token, for recognition. }
        default_route_group_id: { type: [string, "null"] }
        max_concurrency: { type: [integer, "null"] }
        created_at: { type: string, format: date-time }
        last_used_at: { type: [string, "null"], format: date-time }
        revoked_at: { type: [string, "null"], format: date-time }
        token_revealable:
          type: boolean
          description: True for the automatically created access point until its token has been shown once.
    AccessPointWithToken:
      type: object
      required: [access_point, token]
      properties:
        access_point: { $ref: "#/components/schemas/AccessPoint" }
        token: { type: string, description: "`asl_` followed by 32 characters. Shown once." }

    Batch:
      type: object
      required: [id, tier, seats, billing_state, cancel_at_period_end, current_period_start, current_period_end]
      properties:
        id: { type: string }
        tier: { $ref: "#/components/schemas/SeatTier" }
        seats: { type: integer }
        billing_state: { type: string, enum: [active, past_due, suspended, expired] }
        complimentary: { type: boolean }
        cancel_at_period_end: { type: boolean }
        current_period_start: { type: string, format: date-time }
        current_period_end:
          type: string
          format: date-time
          description: End of the paid period. A prepaid batch renewed early has a current period that starts in the future.
        grace_until: { type: [string, "null"], format: date-time }
        suspend_until: { type: [string, "null"], format: date-time }
        renewal: { $ref: "#/components/schemas/Renewal" }
    Renewal:
      type: string
      enum: [auto, prepaid, none]
      description: |
        `auto`: the payment provider renews the subscription every month (manage it in the portal);
        `prepaid`: the period is paid in advance with stablecoins and renewed with a renewal checkout;
        `none`: complimentary seats that end with their period.
    PaymentMethodKind:
      type: string
      enum: [card, crypto]
      description: "`card`: card and wallet payments through Creem, renewed automatically; `crypto`: USD stablecoins (USDC, USDP, USDG) through Dodo Payments, prepaid."
    Billing:
      type: object
      required: [seats, batches, payments, prices, checkout_enabled, payment_methods, pending_orders]
      properties:
        seats: { $ref: "#/components/schemas/Seats" }
        checkout_enabled: { type: boolean, description: Whether card checkout is available. }
        payment_methods:
          type: array
          items:
            type: object
            required: [method, enabled, renewal]
            properties:
              method: { $ref: "#/components/schemas/PaymentMethodKind" }
              enabled: { type: boolean }
              renewal: { $ref: "#/components/schemas/Renewal" }
              months:
                type: array
                description: Prepaid terms in months that a crypto checkout can cover.
                items: { type: integer }
        pending_orders:
          type: array
          description: Stablecoin checkouts of the last seven days that are waiting for their payment, newest first.
          items:
            type: object
            required: [id, tier, region, units, months, amount_minor, currency, created_at]
            properties:
              id: { type: string }
              tier: { $ref: "#/components/schemas/SeatTier" }
              region: { type: string }
              units: { type: integer }
              months: { type: integer }
              amount_minor: { type: integer, description: Quote in minor units of `currency`. }
              currency: { type: string }
              target_batch_id: { type: [string, "null"], description: The batch a renewal extends; null for new seats. }
              provider_status:
                type: [string, "null"]
                description: Latest payment status reported by Dodo Payments, for example `processing`, `requires_customer_action`.
              created_at: { type: string, format: date-time }
        prices:
          type: object
          description: Monthly price per seat in minor units (cents), by tier.
          required: [currency, pro, basic]
          properties:
            currency: { type: string, example: USD }
            pro: { type: integer, example: 1900 }
            basic: { type: integer, example: 900 }
        batches:
          type: array
          description: Batches that are not expired, newest first.
          items: { $ref: "#/components/schemas/Batch" }
        payments:
          type: array
          items:
            type: object
            required: [id, batch_id, kind, amount_minor, currency, created_at]
            properties:
              id: { type: string }
              batch_id: { type: string }
              kind: { type: string, enum: [initial, renewal, refund] }
              amount_minor: { type: integer }
              currency: { type: string }
              provider: { type: string, enum: [creem, dodo] }
              created_at: { type: string, format: date-time }

    Usage:
      type: object
      required: [window, totals, series]
      properties:
        window: { type: string, enum: [1h, 24h, 7d] }
        totals: { $ref: "#/components/schemas/UsageTotals" }
        series:
          type: array
          description: Buckets of 1 minute (1h), 15 minutes (24h) or 2 hours (7d), oldest first, including empty buckets.
          items:
            allOf:
              - type: object
                required: [t]
                properties:
                  t: { type: string, format: date-time }
              - $ref: "#/components/schemas/UsageTotals"
    UsageTotals:
      type: object
      required: [requests, successes, errors, input_tokens, output_tokens, cache_read_tokens]
      properties:
        requests: { type: integer }
        successes: { type: integer }
        errors:
          type: object
          description: |
            Failed requests by cause. Keys are the slot error classes (`rate_limited`,
            `insufficient_balance`, `credential_invalid`, `upstream_unavailable`,
            `egress_unavailable`, `not_ready`, `client_request`) and the gateway's own error types
            listed on the documentation's troubleshooting page (for example `invalid_request`,
            `instance_suspended`, `no_available_instance`).
          additionalProperties: { type: integer }
        input_tokens: { type: integer }
        output_tokens: { type: integer }
        cache_read_tokens: { type: integer }
        cache_hit_rate: { type: [number, "null"], description: Cache read tokens over input tokens. }
        upload_p50_ms: { type: [integer, "null"] }
        ttft_p50_ms: { type: [integer, "null"] }
        ttft_p95_ms: { type: [integer, "null"] }
        output_tokens_per_second: { type: [number, "null"] }

    Notification:
      type: object
      required: [id, kind, title, body, created_at]
      properties:
        id: { type: string }
        kind:
          type: string
          description: "e.g. payment_failed, payment_recovered, batch_suspended, batch_expired, renew_via_checkout, expiry_warning, credentials_outdated, instance_failed"
        title: { type: string }
        body: { type: string }
        link: { type: [string, "null"], description: Dashboard path the notification refers to. }
        created_at: { type: string, format: date-time }
        read_at: { type: [string, "null"], format: date-time }

    Settings:
      type: object
      required: [workspace_name, email_notifications]
      properties:
        workspace_name:
          type: string
          description: Account name (wire key kept for backward compatibility).
        email_notifications:
          type: boolean
          description: Send billing and credential notices by email as well as in the dashboard.
    SettingsUpdate:
      type: object
      required: [email_notifications]
      properties:
        workspace_name:
          type: string
          description: Optional account name; when omitted or empty, the existing name is preserved.
        name:
          type: string
          description: Alias for `workspace_name`; preserved when omitted.
        email_notifications:
          type: boolean
          description: Send billing and credential notices by email as well as in the dashboard.
