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

# Connect an agent

> Connects one new agent to a vault and returns its credential once. Called with the vault's connect token, or by a person who names the vault.

Takes a vault's connect token (`oc_connect_...`), or a person's managing key or signed-in session. See the [Quickstart](/docs/quickstart.md) for connecting an agent.

Connects one new agent to a vault and returns its credential once. Called with a connect token of the vault (the vault is the token's), or by a person with a key that has manage and a vaultId. A one-use connect token connects one agent and then stops: a second call with it is 401, as for a token that expired or was turned off. A place that already holds an agent's credential sends it in OneCLI-Agent-Credential: one place holds one agent, on one vault.

> [!NOTE]
>
> **Availability:** OneCLI Cloud and self-hosted.


## OpenAPI

````yaml /openapi.yaml post /v2/agents
openapi: 3.1.0
info:
  title: OneCLI API
  version: '2'
  description: >
    The OneCLI API manages what the gateway enforces: vaults, the items in them,
    the agents connected to them, what agents may do with each item,
    organization rules, approvals and activity.


    **Base URL:** `https://api.onecli.sh` (OneCLI Cloud) or your own
    deployment's address (`http://localhost:10254` by default). Every path
    starts with `/v2`.


    ## Authentication


    Send `Authorization: Bearer <credential>`. Which credential an endpoint
    takes is on its page.


    - **Managing key** (`oc_key_...`): acts as the person who made it, in the
    organization it was made in.

    - **Agent credential** (`oc_agent_...`): reads what that agent can use and
    nothing else. On an endpoint for a person it answers `403` with the detail
    `person_required`.

    - **Connect token** (`oc_connect_...`): connects one agent to its own vault
    and does nothing else.

    - **Signed-in session**: the dashboard's own. A few endpoints take a session
    only and refuse every key.


    ## Editions


    Endpoints marked **Cloud** exist on OneCLI Cloud only. Every other endpoint
    exists on OneCLI Cloud and on a self-hosted deployment.
servers:
  - url: https://api.onecli.sh
    description: OneCLI Cloud
  - url: http://localhost:10254
    description: Self-hosted
security: []
tags:
  - name: Vaults
    description: A vault holds items and has agents connected to it.
  - name: Items
    description: >-
      The connected apps, API keys and LLM keys in a vault. Values are
      write-only.
  - name: Permissions
    description: What the agents on a vault may do with one item, per tool.
  - name: Connect tokens
    description: The tokens that connect a new agent to a vault.
  - name: Agents
    description: The agents connected to the vaults you can use.
  - name: Agent sign-ups
    description: How an agent with no credential asks a person to connect it.
  - name: Agent self-service
    description: What an agent reads about itself with its own credential.
  - name: Approvals
    description: The requests the gateway holds until a person answers.
  - name: Rules
    description: 'Organization rules: block, require approval, or rate-limit.'
  - name: Activity
    description: 'What agents did: the request log, usage counts and the audit log.'
  - name: Apps
    description: The apps that can be connected, and the organization's own OAuth apps.
  - name: API keys
    description: 'Managing keys: the keys a person''s scripts call this API with.'
  - name: Organization
    description: You, your organizations, and an organization's name and logo.
  - name: Utility
    description: Health check.
  - name: Members
    description: The people of an organization and their roles.
  - name: Invites
    description: Invite people to an organization by email.
  - name: Groups
    description: Groups of members, used to share vaults and to set roles.
  - name: Vault sharing
    description: The people and groups a vault is shared with.
  - name: Shared items
    description: Items an organization keeps once and shares with chosen vaults.
  - name: Sign-in
    description: 'Single sign-on: identity provider connections, domains and enforcement.'
  - name: Directory tokens
    description: Tokens the organization's directory syncs people and groups with.
  - name: LLM sign-in
    description: Add a Claude or ChatGPT subscription to a vault by signing in.
  - name: Billing
    description: The organization's plan, credits and payment state.
  - name: Support
    description: Write to the OneCLI team, or ask for an app.
paths:
  /v2/agents:
    post:
      tags:
        - Agents
      summary: Connect an agent
      description: >-
        Connects one new agent to a vault and returns its credential once.
        Called with a connect token of the vault (the vault is the token's), or
        by a person with a key that has manage and a vaultId. A one-use connect
        token connects one agent and then stops: a second call with it is 401,
        as for a token that expired or was turned off. A place that already
        holds an agent's credential sends it in OneCLI-Agent-Credential: one
        place holds one agent, on one vault.
      operationId: postAgents
      parameters:
        - description: >-
            Optional. The agent credential this place already holds. On this
            vault: 200 with that agent and nothing made. On another vault: 409,
            or with replace that agent is disconnected and a new one is made. A
            credential that no longer works, or is not known, is ignored.
          in: header
          name: OneCLI-Agent-Credential
          required: false
          schema:
            maxLength: 255
            type: string
        - description: Not accepted on this call. Sending it is 400 bad_request.
          in: header
          name: Idempotency-Key
          required: false
          schema:
            maxLength: 255
            minLength: 1
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateAgent'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/KeptAgent'
          description: >-
            This place is connected to this vault already. The agent, with no
            credential: the place holds it.
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreatedAgent'
          description: The new agent, with its credential shown once.
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Bad request.
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Not signed in.
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Not allowed.
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: No such vault that you can use.
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: >-
            An agent with this name is already connected to this vault, the
            vault is from before 3.0 and has not been moved yet, this place
            holds an agent on another vault (details: agent_on_other_vault), or
            another call disconnected that agent first.
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Validation failed.
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Unexpected error.
        '503':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: >-
            This server cannot make a credential: its CREDENTIAL_PEPPER_SECRET
            setting is missing or too short.
      security:
        - connectBearer: []
        - userBearer: []
components:
  schemas:
    CreateAgent:
      additionalProperties: false
      properties:
        expiresAt:
          description: >-
            ISO 8601, at least 5 minutes and at most 90 days ahead. Unset: no
            expiry.
          format: date-time
          type: string
        host:
          description: >-
            The machine's host name. With no name, the agent is named after it
            (with 4 hex characters added when that name is taken on the vault).
          maxLength: 64
          minLength: 1
          pattern: ^[^\p{Cc}]+$/u
          type: string
        name:
          description: >-
            1 to 64 characters. Unset: the server names the agent after host, or
            from the runtime and 4 hex characters. With a one-use connect token
            that fixes a name, the token's is used.
          maxLength: 64
          minLength: 1
          pattern: ^[^\p{Cc}]+$/u
          type: string
        provider:
          description: >-
            The agent's provider: a short lowercase label that never decides
            access. With a one-use connect token that fixes a provider, the
            token's is used.
          example: boat
          pattern: ^[a-z0-9][a-z0-9._-]{0,31}$
          type: string
        replace:
          default: false
          description: >-
            Used only when the OneCLI-Agent-Credential header names an agent on
            another vault. true: disconnect that agent and connect a new one
            here.
          type: boolean
        runtime:
          default: linux
          description: 'What the agent runs on. Default: linux.'
          enum:
            - docker
            - linux
            - macos
            - windows
          type: string
        vaultId:
          description: >-
            The vault to connect to. Required with a key or a session. Not taken
            with a connect token, whose vault is fixed.
          maxLength: 64
          minLength: 1
          type: string
      type: object
    KeptAgent:
      properties:
        createdAt:
          description: ISO 8601.
          type: string
        expiresAt:
          description: >-
            ISO 8601. When the agent's credential stops by itself. null: it
            stops only when the agent is disconnected.
          type:
            - string
            - 'null'
        gateway:
          $ref: '#/components/schemas/AgentGateway'
        id:
          type: string
        name:
          type: string
        provider:
          description: >-
            The agent's provider: a short lowercase label. It never decides
            access. null: not known.
          example: boat
          pattern: ^[a-z0-9][a-z0-9._-]{0,31}$
          type:
            - string
            - 'null'
        runtime:
          description: 'What the agent runs on. null: not known yet.'
          type:
            - string
            - 'null'
        vaultId:
          type: string
      required:
        - id
        - name
        - vaultId
        - runtime
        - provider
        - createdAt
        - expiresAt
        - gateway
      type: object
    CreatedAgent:
      properties:
        createdAt:
          description: ISO 8601.
          type: string
        credential:
          description: >-
            The agent's credential (oc_agent_...). Shown here once. Store it
            now: it cannot be read again.
          example: oc_agent_exampleexampl_example
          type: string
        expiresAt:
          description: >-
            ISO 8601. When the agent's credential stops by itself. null: it
            stops only when the agent is disconnected.
          type:
            - string
            - 'null'
        gateway:
          $ref: '#/components/schemas/AgentGateway'
        id:
          type: string
        name:
          type: string
        provider:
          description: >-
            The agent's provider: a short lowercase label. It never decides
            access. null: not known.
          example: boat
          pattern: ^[a-z0-9][a-z0-9._-]{0,31}$
          type:
            - string
            - 'null'
        runtime:
          description: 'What the agent runs on. null: not known yet.'
          type:
            - string
            - 'null'
        vaultId:
          type: string
      required:
        - id
        - name
        - vaultId
        - runtime
        - provider
        - createdAt
        - expiresAt
        - gateway
        - credential
      type: object
    Error:
      properties:
        error:
          properties:
            code:
              enum:
                - bad_request
                - validation_failed
                - unauthenticated
                - forbidden
                - not_found
                - conflict
                - gone
                - idempotency_conflict
                - precondition_required
                - rate_limited
                - authorization_pending
                - slow_down
                - access_denied
                - expired_token
                - internal
                - unavailable
              type: string
            details:
              items:
                $ref: '#/components/schemas/ErrorDetail'
              type: array
            message:
              type: string
            requestId:
              description: The X-Request-Id of this call, to quote when asking.
              type:
                - string
                - 'null'
          required:
            - code
            - message
            - details
            - requestId
          type: object
      required:
        - error
      type: object
    AgentGateway:
      description: >-
        Where the agent reaches the gateway. Build the proxy URL from this and
        decide nothing yourself.
      properties:
        address:
          description: The gateway's host and port, with no scheme.
          example: gateway.onecli.sh:443
          type: string
        scheme:
          description: >-
            The scheme of the proxy URL the agent uses: https where the gateway
            ends TLS for agents, else http. Use it as given.
          enum:
            - http
            - https
          example: https
          type: string
      required:
        - address
        - scheme
      type: object
    ErrorDetail:
      properties:
        field:
          description: Where the problem is.
          type: string
        issue:
          description: What kind of problem.
          type: string
        message:
          description: The problem in words.
          type: string
      required:
        - field
        - issue
        - message
      type: object
  securitySchemes:
    connectBearer:
      description: >-
        A vault's connect token (oc_connect_...). It connects one agent to its
        own vault and does nothing else.
      scheme: bearer
      type: http
    userBearer:
      description: >-
        A managing key (oc_key_...), an older API key (oc_...), or a signed-in
        session.
      scheme: bearer
      type: http

````

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