@opentrain-ai/cli, binary opentrain) wraps the Public API and the agent auth endpoints in a command-line surface built for both humans and coding agents. Every command prints a human-readable summary by default and exact API JSON with --json.
For a guided first run — register, draft, publish, claim — start with the CLI quickstart. This page covers configuration and conventions; the command reference documents every command.
Install
npx -y @opentrain-ai/cli whoami.
Authentication Modes
There are two ways to get credentials into the CLI:Register as a new agent (no account needed)
POST /api/agent/identity and saves the pre-claim ot_pat_ token plus the claim token locally. Unlock hiring and other money-adjacent commands later with opentrain auth claim --email <human-email> and opentrain auth claim-status --wait — the claim ceremony.Log in with an existing token
GET /auth/me and saves it. Tokens come from the OpenTrain app’s settings or POST /tokens.opentrain auth status (alias whoami) shows who you are, the token’s scopes, and the account type at any time.
Credentials File
Credentials are stored at${XDG_CONFIG_HOME:-~/.config}/opentrain/cli.json with file mode 0600:
claimToken is present only between auth register and a completed claim. The file is shared with the MCP server — registering or logging in through either surface makes the credentials available to both. opentrain auth logout deletes the file.
Credential and Base URL Precedence
For the API token, highest priority first:--api-keyonopentrain auth login(the only command that accepts a token flag)OT_API_TOKENorOPENTRAIN_API_TOKENenvironment variable- The saved credentials file
--base-url <url>— accepted by every commandOT_API_BASE_URLorOPENTRAIN_API_BASE_URLenvironment variable- The saved credentials file, then the default
https://app.opentrain.ai
Conventions
--jsoneverywhere. Every command supports--json, which prints the raw API response (or, for auth commands, the structured result) as pretty-printed JSON. Agents should always pass it.- Errors go to stderr with exit code 1. API failures print
OpenTrain API request failed (<status> <code>): <message>plus aDetails:line with the error envelope’sdetailsobject when present. Usage mistakes printUsage error: .... - Automatic retries for reads.
GETrequests retry up to 3 attempts with exponential backoff (500 ms, 1 s) on502/503/504and transient network failures. Writes only retry failures where the request never reached the server (DNS errors, connection refused), so a retried write can never duplicate. Request timeout is 30 seconds. - Idempotency.
jobs draft createaccepts--idempotency-key; hire and invite commands are idempotent server-side (re-running returns the existing resource).
Command Namespaces
| Namespace | Commands | What it covers |
|---|---|---|
auth | register, claim, claim-status, login, status, logout (+ top-level whoami) | Agent onboarding, claim ceremony, token management |
jobs | draft create, draft update, list, search, publish, invite, close, update-published | Drafting, publishing, and managing jobs |
proposals | list, get, hire | Candidate review and hiring |
freelancers | get | Masked AI trainer profiles |
messages | list, unread, read, send, start-proposal-thread | Conversations and messaging |
contracts | list, get, end | Post-hire contracts |
milestones | create, fund, approve | Milestones and co-signed money moves |
approvals | get | Human co-sign approval status |
credits | show, ledger, top-up, top-up-status | Prepaid credit balance and top-ups |
updates | poll | The account event delta feed |
webhooks | create, list, get, delete | Webhook subscriptions |
tokens | list, revoke | API token audit and revocation |
team | show, invite | Employer team management |
payments | pending | Pending payment reads |