@onecli-sh/sdk
View on npm
Requirements
| SDK version | Node.js version |
|---|---|
| >= 0.1.0 | >= 20 |
Installation
Quick start
Environment variables
Instead of passing options explicitly, set environment variables:API reference
OneCLI
Main SDK client.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
apiKey | string | process.env.ONECLI_API_KEY | API key (must start with oc_) |
url | string | process.env.ONECLI_URL | Base URL of the OneCLI instance |
timeout | number | 5000 | Request timeout in milliseconds |
gatewayUrl | string | process.env.ONECLI_GATEWAY_URL | Gateway URL for manual approval polling (auto-resolved if not set) |
onecli.getContainerConfig()
Fetch the raw container configuration from OneCLI.
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.
| Parameter | Type | Default | Description |
|---|---|---|---|
combineCaBundle | boolean | true | Build combined CA bundle for system-wide trust |
addHostMapping | boolean | true | Add host.docker.internal mapping on Linux |
- 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.
Manual Approval
onecli.configureManualApproval(callback)
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
| Field | Type | Description |
|---|---|---|
id | string | Unique approval ID |
method | string | HTTP method (GET, POST, DELETE, etc.) |
url | string | Full request URL |
host | string | Hostname |
path | string | Request path |
headers | Record<string, string> | Sanitized request headers (no credentials) |
bodyPreview | string | null | First 4KB of the request body, or null if no body |
agent | { id: string; name: string; externalId: string | null } | The agent that made the request |
createdAt | string | When the request arrived (ISO 8601) |
expiresAt | string | When the approval expires (ISO 8601) |
timeoutSeconds | number | Seconds until auto-deny (300) |
ManualApprovalHandle
| Method | Description |
|---|---|
stop() | Stop polling and disconnect |
Manual approval requires a policy rule with the Manual Approval action configured in the dashboard. Without a matching rule, no requests are held for approval.
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.