@onecli-sh/sdk
View on npm
Requirements
Installation
Quick start
- Cloud
- Self-hosted
Environment variables
Instead of passing options explicitly, set environment variables:- Cloud
- Self-hosted
Organization API keys
Organization-level API keys (oc_org_...) grant access across all projects in an org. Pass a projectId to specify which project to target.
projectId can also be set via the ONECLI_PROJECT_ID environment variable. Per-operation overrides always take precedence over the constructor default.
API reference
OneCLI
Main SDK client.
Parameters
onecli.getContainerConfig(options?)
Fetch the raw container configuration from OneCLI.
Returns
OneCLIRequestError if OneCLI returns a non-200 response.
onecli.applyContainerConfig(args, options?)
Fetch the container config and push Docker flags onto the args array. Returns true if config was applied, false if OneCLI was unreachable.
This method:
- Fetches
/api/container-configfrom OneCLI with Bearer auth - Pushes
-e KEY=VALUEfor each environment variable - Writes the CA certificate to a temp file and mounts it with
-v - Builds a combined CA bundle (system CAs + OneCLI CA) so all tools trust OneCLI
- Adds
--add-host host.docker.internal:host-gatewayon Linux
false without mutating the args array.
Project provisioning
Project provisioning is a cloud-only feature. Calling
provisionProject() against an OSS instance throws OneCLIError.onecli.provisionProject(input?, options?)
Pre-create a user account with a project and API key. The API key works immediately. Requires admin or owner role.
Options
Returns:
ProvisionProjectResponse
Throws
OneCLIError if called against an OSS instance. Throws OneCLIRequestError with status 403 if the API key doesn’t belong to an admin/owner.
See the User Provisioning guide for the full workflow.
Manual approval
onecli.configureManualApproval(callback, options?)
Register a callback that’s invoked whenever an agent request needs human approval. Starts background long-polling to the gateway. Returns a handle to stop polling.
ApprovalRequest
Return value:
ManualApprovalHandle
Manual approval requires an allow policy rule with Require approval set. Without a matching rule, no requests are held for approval.
Org policy rules
Author and publish organization policy rules (the staged draft → publish model; see the Policy rules guide). Writes publish automatically; pass{ skipPublish: true } to stage and review first, since a publish snapshots the whole org draft, including changes staged by other users.
The legacy
createRule/updateRule/deleteRule methods are deprecated: OneCLI Cloud rejects them with 410 Gone; self-hosted servers that have not cut over still accept them.
onecli.org.configureManualApproval(callback, options?)
Organization-scoped approvals require an organization API key (
oc_org_...) and OneCLI Cloud or a self-hosted Enterprise instance.onecli.configureManualApproval, with two differences: the poll carries no X-Project-Id (the organization is derived from the key), and each request includes its own projectId, which the SDK uses to route the decision back to the right project.
OrgApprovalRequest
Every field of ApprovalRequest (above), plus:
Options
Return value:
ManualApprovalHandle (the same stop() handle as the project handler).
Error classes
OneCLIError
General SDK error (e.g., missing API key).
OneCLIRequestError
HTTP request error with additional context.
Types
All types are exported for use in your own code:How it works
OneCLI runs on the host machine and acts as a gateway for containerized agents. When a container makes HTTPS requests to intercepted domains (e.g.api.anthropic.com), OneCLI:
- Terminates TLS using a local CA certificate
- Inspects the request and injects real credentials (replacing placeholder tokens)
- Forwards the request to the upstream service
- Returns the response to the container
HTTPS_PROXY, HTTP_PROXY) and CA certificate mounts so this works automatically.