CLI
Connect Claude Code, Codex, OpenCode, Cline, OpenClaude, OpenClaw, Hermes Agent, zero or ZCode to AI/ML API with one command using the aimlapi CLI.
aimlapi is the AI/ML API command-line tool. It signs you in through the browser, creates an API key for you, and starts your coding agent already connected to AI/ML API:
npx aimlapi claudeYou don't copy a key or edit config files by hand. Usage is billed to your AI/ML API account like any other API request.
Supported agents
Supported platforms: macOS, Linux and Windows, on x64 and arm64.
Install
You need an AI/ML API account with a positive balance. You can top up at https://aimlapi.com/app/billing.
Needs Node.js 18+ and npm.
npx aimlapi <command>Needs Node.js 18+ and npm.
npm i -g aimlapi
aimlapi <command>curl -fsSL https://aimlapi.com/install.sh | shInstalls aimlapi into ~/.local/bin. If that directory is not on your PATH, the script prints the line to add to your shell's rc file (it never edits rc files).
In PowerShell:
irm https://aimlapi.com/install.ps1 | iexInstalls aimlapi into %LOCALAPPDATA%\aimlapi\bin and adds that directory to your user PATH. Open a new terminal afterwards.
The command is called aimlapi, and the examples on this page use it. If you run the CLI through npx, use npx aimlapi in its place.
Install scripts. They download the same binary that
npm i -g aimlapiinstalls from the npm registry, check its sha512 and install it withoutsudo. Settings (environment variables):AIMLAPI_INSTALL_DIR(another directory),AIMLAPI_VERSION(a specific version, defaultlatest),AIMLAPI_NPM_REGISTRY, and on WindowsAIMLAPI_INSTALL_NO_MODIFY_PATH=1(don't touchPATH).Alias. The npm package
aimlapi-cliis an alias ofaimlapiwith the sameaimlapicommand (npx aimlapi-cli claude,npm i -g aimlapi-cli). Install only one of the two globally.Updates. Once a day the CLI checks for a new release and prints a one-line notice (outside agent sessions it may also offer to update right away).
aimlapi updateupdates it the way it was installed: withnpm i -g aimlapi@latest(oraimlapi-cli@latest) for an npm install, or by downloading, verifying and replacing the binary for a script install. It only moves to a newer release. Through npx there is nothing to update; runnpx aimlapi@latest <command>to get the newest version. To turn the check off, setAIMLAPI_NO_UPDATE_CHECK=1; it is also off whenCI=true.
Quick start
Install the agent (only if it's missing)
If the agent isn't installed, aimlapi shows the exact install command and asks, for example:
See Missing agents.
Sign in (first run only)
If no key is stored yet, the CLI opens your browser. Sign in to AI/ML API and approve the aimlapi CLI. On that page you can also set an optional USD limit for the new key. The key is created and saved on your computer. The CLI also prints the link, in case the browser doesn't open.
Agent commands
Every agent takes the same flags:
(none)
Configures the agent for this run and starts it.
--model <id>
The model to use. Without it, the CLI reuses the model you picked last for this agent; the first time, you get a picker in an interactive terminal, otherwise (no terminal, or CI=true) the default model. An id that isn't a preset is checked against the catalog.
--config
Saves the configuration into the agent's own config files and exits, so the agent uses AI/ML API when you start it directly.
--undo
Reverts what the CLI wrote into the agent's config files and puts back the values it replaced. Works even when the agent is no longer installed.
--force
With --undo: restore files even if they were edited after the CLI wrote them.
--dry-run
Prints what would happen (environment variables, file diffs, the command line) with secrets masked, and changes nothing. Combine it with --config or --undo to preview them.
--yes, -y
Installs a missing agent with npm without asking.
-- <agent arguments>
Everything after -- is passed to the agent unchanged.
What the CLI changes and keeps safe:
The API key never appears on a command line. The agent gets it from a credential helper (
aimlapi key print), from an environment variable of the agent process only, or from the agent's own config or credential store (mode0600), or, for OpenClaw, from aimlapi's credentials file.Before writing any agent file, the CLI copies the original to
~/.aimlapi/backups/<agent>/<timestamp>/. A repeated run that changes nothing writes nothing.The CLI only changes the settings it owns. Other settings in the file stay as they are, and a value it replaces is restored by
--undo.
Missing agents
When the agent isn't installed, aimlapi offers to install its official npm package and prints the exact command first. Press Enter (or type y) to install; the run then goes on with the model picker and the launch.
It asks only in an interactive terminal (and not when
CIis set).--yesinstalls without asking, also in CI.Without a terminal, with
CIset, with--dry-run, or when you decline, it only prints the command and exits with code4.npm runs in your environment without the CLI's variables (no API key) and never with
sudo. On anEACCESerror, the CLI suggests a user-writable npm prefix. If npm's globalbindirectory is not on yourPATH, it names that directory.Hermes Agent (installed by its own script) and ZCode (the
zcodecommand is built from source) are not installed automatically: the CLI prints how to install them. Node.js isn't installed either.
Model presets
The picker offers the agent's presets first:
Anthropic:
anthropic/claude-sonnet-5,anthropic/claude-opus-5,anthropic/claude-opus-5.5,anthropic/claude-haiku-4.5, for every agent except Codex and ZCode.OpenAI:
openai/gpt-5.6-sol,openai/gpt-5.6-terra,openai/gpt-6-astra, for Codex, OpenCode, Cline, OpenClaw, Hermes Agent and zero.GLM:
zhipu/glm-5.3,z-ai/glm-5.3-flash,zhipu/glm-5.2,zhipu/glm-5.1,z-ai/glm-5-turbo, for ZCode.
You can pass any other model from aimlapi models --agent <agent> with --model.
Claude Code
Launch. Runs claude --settings '<json>' --model <model>. The inline settings contain an env block (base URL https://api.aimlapi.com, the model slots, tracking headers) and apiKeyHelper, which Claude Code runs to get the key from aimlapi key print. Settings on the command line take priority over your settings files, so no file is written. ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN are set to empty, so an Anthropic key exported in your shell is never sent to AI/ML API.
Model slots. --model also accepts the Claude Code tier aliases:
opus
anthropic/claude-opus-5.5
sonnet
anthropic/claude-sonnet-5
haiku
anthropic/claude-haiku-4.5
subagents
anthropic/claude-sonnet-5
--config. Merges the same env keys and apiKeyHelper into ~/.claude/settings.json (or $CLAUDE_CONFIG_DIR/settings.json). Needs an installed aimlapi, not npx.
After aimlapi claude --config, every Claude Code session goes through AI/ML API and is billed to your AI/ML API account, including a plain claude started from any terminal, until you run aimlapi claude --undo.
Codex
Launch. Runs codex with -c overrides that add the model provider aimlapi-cli (Responses API at https://api.aimlapi.com/v1, tracking headers). Codex gets the key by running aimlapi key print. No file is written.
--config. Writes a separate profile, ~/.codex/aimlapi.config.toml (or $CODEX_HOME/aimlapi.config.toml), without the key. Your config.toml is never modified, and a plain codex works as before. Start Codex with the profile:
--undo deletes the profile, or puts back a profile of yours that --config replaced.
OpenCode
Launch. Runs opencode with an inline config in OPENCODE_CONFIG_CONTENT (provider aimlapi-cli, shown as AIMLAPI, OpenAI-compatible at https://api.aimlapi.com/v1, the preset models) and the key in AIMLAPI_API_KEY of the OpenCode process only. No file is written. Models appear as aimlapi-cli/<model id>, for example aimlapi-cli/anthropic/claude-sonnet-5.
--config. Adds the provider (without the key) to OpenCode's global config (~/.config/opencode/opencode.json, or opencode.jsonc, or $OPENCODE_CONFIG) and stores the key in OpenCode's credential store auth.json (mode 0600). It sets the default model only if you have none; otherwise pick an aimlapi-cli/… model with /models. After --config, a launch keeps the stored key current.
Cline
Every run writes Cline's provider store ~/.cline/data/settings/providers.json (mode 0600), because Cline has no flag for a base URL: the built-in OpenAI Compatible provider gets https://api.aimlapi.com/v1, the key, the model and tracking headers, and becomes Cline's default. A launch then runs cline -P openai-compatible -m <model>; --config stops after the write.
The Cline CLI, the Cline VS Code extension and the JetBrains plugin share this provider store. After any aimlapi cline run, all of them use AI/ML API by default until you run aimlapi cline --undo. Cline keeps only one OpenAI Compatible provider: if you had one for another endpoint, the CLI replaces it and --undo puts it back. If the VS Code extension is open, reload the window (Command Palette → Developer: Reload Window).
aimlapi cline needs the cline command even if you only use the VS Code extension. It finds the provider store the way Cline does (CLINE_PROVIDER_SETTINGS_PATH, CLINE_DATA_DIR, CLINE_DIR, and --config <dir> / --data-dir <dir> after --); run --undo with the same settings.
OpenClaude
Launch. Connects OpenClaude over AI/ML API's Anthropic-compatible route (/v1/messages): the base URL, model slots (the same as for Claude Code) and tracking headers are set in its environment, and the key in ANTHROPIC_AUTH_TOKEN of the OpenClaude process only. No file is written. OpenClaude's built-in aimlapi.com preset is not used, and AIMLAPI_API_KEY is removed from the session.
--config. Writes the same variables, with the key, into the env of ~/.openclaude/settings.json (or $OPENCLAUDE_CONFIG_DIR/settings.json, mode 0600); after --config, a launch keeps the stored key current. Picking another provider with /provider later removes only part of these settings; to remove them, run aimlapi openclaude --undo.
OpenClaw
OpenClaw has no per-run provider switch, so every run writes its config (~/.openclaw/openclaw.json, or the file $OPENCLAW_CONFIG_PATH, $OPENCLAW_STATE_DIR or a --profile <name> after -- selects): the OpenAI-compatible provider aimlapi-cli with the preset models, and the default model aimlapi-cli/<model>. A launch then starts openclaw; --config only writes. A running Gateway reloads the config by itself.
The key is not copied into openclaw.json: OpenClaw reads it from the CLI's credentials file. So sign in with aimlapi login first (AIMLAPI_API_KEY alone is not enough, exit code 3), and run openclaw secrets reload after you log in with a new key or log out.
Hermes Agent
Hermes Agent is installed with its own script, not npm (curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash; the CLI prints the Windows command). Hermes has no per-run provider switch, so the CLI adds named custom providers (OpenAI-compatible, the preset models) to Hermes' config.yaml (~/.hermes, $HERMES_HOME, or the active Hermes profile). The key is not copied: Hermes runs aimlapi key print to get it.
Launch writes the entry
aimlapi-cli-runand startshermes --provider custom:aimlapi-cli-run -m <model>, so a plainhermeskeeps its default.--configwrites the entryaimlapi-cliand makes it Hermes' default model. Needs an installedaimlapi, not npx. A running Hermes gateway needshermes gateway restart.--undoremoves both entries and puts back themodel:keys they replaced. Only those lines ofconfig.yamlchange.
zero
zero has no flag for a provider, so every run writes the OpenAI-compatible provider profile aimlapi-cli into zero's config (~/.config/zero/config.json, or $XDG_CONFIG_HOME/zero/config.json; on Windows %AppData%\zero\config.json). zero's built-in aimlapi preset is not used. The profile reads the key from AIMLAPI_CLI_KEY, so no key is written: a launch sets it for the zero process only. --config also makes the profile zero's default provider.
After aimlapi zero --config, aimlapi zero works as is, but a plain zero needs AIMLAPI_CLI_KEY in your shell. With an installed aimlapi (not npx), add this line to your shell profile:
Without it, zero silently uses another provider it has a key for. Don't export AIMLAPI_API_KEY for this: it overrides the key saved by aimlapi login for every aimlapi command.
ZCode
ZCode is Z.ai's coding agent for GLM models. aimlapi zcode needs ZCode's terminal command zcode, which Z.ai does not publish as a package: build it from source. The CLI adds the OpenAI-compatible provider aimlapi-cli (shown as AI/ML API) with the GLM presets; ZCode keeps the key in its provider config (mode 0600).
Launch gives
zcodea provider config of the CLI's own ($ZCODE_PERSONAL_PROVIDER_CONFIG_FILE), so your~/.zcodeis not changed. A provider you add inside such a session is saved into that file and is gone after--undoorlogout: add your own providers in a plainzcodesession or the desktop app.zcode --webcan't be started this way; use--config.--configadds the provider to~/.zcode/v2/provider_config.json(or$ZCODE_DATA_BASE_DIR/.zcode/v2), shared by the ZCode desktop app,zcodeandzcode --web, and makes its model the default. If the desktop app keeps its data in another folder, that copy is set up too. A running ZCode picks up the change by itself.
Account commands
login
login opens the browser, where you sign in and approve the aimlapi CLI. On the approval page you can set an optional USD limit for the new key and how often it resets. The key is saved to ~/.aimlapi/credentials (file mode 0600; on Windows %APPDATA%\aimlapi\credentials). You don't have to run login first: in an interactive terminal, agent commands start the same sign-in when no key is stored.
The device code flow (--device) prints a link that you open and approve on any device. The CLI picks it automatically over SSH, on Linux without a graphical display, and when it can't open a browser or a local port.
If you log in again, the stored key is replaced, but the previous key stays active. You can revoke it on the API Keys page.
logout
Revokes the stored key on the server and removes it from your computer. Agent configs that hold a copy of that key (OpenCode, Cline, OpenClaude, ZCode) are reverted as aimlapi <agent> --undo would, and the agent config backups are deleted. If the server refuses or can't be reached, the key is still removed locally but may remain active: revoke it on the API Keys page. logout doesn't change AIMLAPI_API_KEY.
status
Shows your account balance and the spend and limit of the API key in use. The key itself is only shown masked.
models
Lists AI/ML API chat models from the public catalog. No login is needed.
Without
--agent, you get every chat model and the agents that can use it.With
--agent <agent>, you get only the models that agent can use: served on the agent's API and supporting tool calling. The agent's presets come first, with the default model and the model slots marked.With
--json, the output is machine-readable.
update
Updates aimlapi to the latest version, through npm or, for a script install, by replacing the binary (see Install).
Set up from your agent
You can also let your coding agent set itself up. Paste this into any of the supported agents:
The agent signs you in through the browser (you approve; you never paste a key into the chat), shows what it will change with --dry-run, applies it after you confirm, and tells you how to undo it.
To install it as a Claude Code skill instead (then just ask Claude Code to "set up AI/ML API"), download the file with its frontmatter:
Troubleshooting
Exit codes
0
Success.
1
General error (network, file, server, agent too old).
2
Invalid arguments, flags or environment values (for example, --config run through npx).
3
Authentication: not logged in, the key is invalid or rejected, or the sign-in was denied.
4
The coding agent is not installed, or its installation failed.
When the agent starts, its own exit code is returned when it finishes.
Environment variables
AIMLAPI_API_KEY
API key to use instead of the one saved by aimlapi login, for every command.
AIMLAPI_CONFIG_DIR
Directory for credentials and backups (default ~/.aimlapi; Windows %APPDATA%\aimlapi).
AIMLAPI_BASE_URL
Overrides the API host (default https://api.aimlapi.com).
AIMLAPI_NO_UPDATE_CHECK
Set to 1 to turn off the daily new-version check.
AIMLAPI_CLI_KEY
The key variable of zero's aimlapi-cli profile (see zero).
CI
When true: no model picker, no inline sign-in, no install prompt, no update check.
HTTPS_PROXY, NO_PROXY
Proxy for the CLI's own requests.
AIMLAPI_INSTALL_DIR, AIMLAPI_VERSION
Install scripts only: target directory and version (see Install).
Last updated
Was this helpful?