poly apikey is the narrower cousin of poly login: it gets you an account-scoped API key for the PolyAI APIs and Dialog RSN, not an ADK setup. It signs you in, creates that key (or reuses the one already in your shell profile), and exports it as POLY_API_KEY into your shell profile.
It is designed for AI coding assistants: with --json (or no terminal) it never prompts, so an agent can run it unattended. The one prompt it has is the account picker, shown only at a terminal without --json when you belong to more than one account. To set up the ADK itself, use poly setup or poly login instead — those are the interactive path for a human at the keyboard, and the ADK reads its credentials from ~/.poly/credentials.json rather than POLY_API_KEY.
Examples:
Key types and expiry
--type picks what the key can call. It maps to the two choices on Agent Studio’s API keys page:
Each type has its own variable, so the two keys live side by side: creating, reusing or replacing a
model key never touches POLY_API_KEY or the ADK credential, since a model key can’t run the ADK. A model key gets its own default name (cli-generated-key-model) so it never collides with your agent key. Read it from POLY_MODEL_API_KEY in your realtime code.
--expires-in sets how long a new key lasts: 30d, 90d (the default), 365d, or never. The expiry is worked out on your machine as an absolute UTC time. When you re-run and the key is reused, the summary shows its type and expiry, and warns you when it expires within 14 days. Once it has expired, the run stops with exit code 2, says when it expired, and tells you to re-run with --force to create a new one. A key that was revoked (it is no longer in the account’s key list) is reported the same way.
poly apikey:
- Signs in via the Auth0 device authorization flow. For
--region studio, this is a dedicated client whose login page shows only “Continue with GitHub”. For any other--region, it’s the same standard sign-in page (email/SSO) thatpoly loginuses. The sign-in is kept in~/.poly/apikey_session(readable only by you) until it expires, so a re-run does not sign you in again;--no-session-cacheskips this. - Calls the authorise endpoint. On
studio, this creates your workspace if you don’t already have one. On an enterprise region (us,uk,eu), your account must already be provisioned by PolyAI — the command stops with a clear message if it isn’t. - Resolves your account id — by default, polls for up to 20 seconds for the newly created account to appear; pass
--account-idto skip this. With more than one account, a terminal shows a picker; otherwise the command stops and lists them so you can re-run with--account-id. - Reuses the key already in your shell profile for that
--type(POLY_API_KEY, orPOLY_MODEL_API_KEYfor--type model) if it works for the account, otherwise creates a new key of the--typeand--expires-inyou asked for. A reused key keeps the expiry it was created with: if you pass--expires-inand the key is reused, the command says it didn’t apply and that--forcecreates a fresh key. It never re-creates a key on its own. It looks the reused key up in the account’s key list (by its first and last four characters) to show its type and expiry, and warns if it expires within 14 days or isn’t the--typeyou asked for. If the platform doesn’t accept your profile’s key for the account (for example because it expired), the command stops without creating anything and tells you to re-run with--force, which creates a new key and replaces it. Unlikepoly login’s Personal Access Token, this key is account-scoped. - Saves an
agentkey to~/.poly/credentials.jsonunder--region— but only if no entry for that region already exists there. Amodelkey is never saved there. An existing ADK credential is never overwritten, and credentials for different regions coexist independently. - Writes
export POLY_API_KEY="..."(POLY_MODEL_API_KEYfor--type model; or, on Windows, sets the variable in your user environment) into your detected shell profile, so new shells and processes pick it up automatically. The ADK itself reads~/.poly/credentials.jsonand doesn’t need this variable; it’s exported for the PolyAI SDKs and other tools that readPOLY_API_KEYdirectly. - Prints a summary with the key masked, ending with the next step: your first API call.
--jsoncarries anext_step_urlfor the Dialog RSN 1 reference. The key and your sign-in token are never printed or logged.
0 on success, 1 on a sign-in, account, or API failure, 2 when the platform doesn’t accept the POLY_API_KEY in your profile for the account and --force was not passed.
Which region should I pick?
--region is required. studio is the self-serve cluster individual developers sign up on via GitHub. Pick a production region (us, uk, eu) only if you already have an enterprise account provisioned there; those regions require signing in through the standard email/SSO login page rather than GitHub, since the GitHub-only client only exists for studio.Windows
Install uv withwinget install astral-sh.uv. If poly is not found after installing, run uv tool update-shell and open a new terminal. POLY_API_KEY is written to your user environment (HKCU\Environment) rather than a shell profile file — it is visible in new terminals and under System Properties → Environment Variables → User variables.
--json output shape:
key_type and expires_at come from the platform: the create response for a new key, or the account’s key list for a reused one, falling back to what was asked for. expires_at is null for a key that never expires. When the key is reused from your profile, key_reused is true and key_name is null; key_type and expires_at are null only if the key isn’t found in the account’s key list. env_var is the variable the key was exported as. warnings lists, as sentences, anything the human output would have warned about: the reused key expires within 14 days, it isn’t the --type you asked for, --expires-in didn’t apply, or the key isn’t active yet. It is empty when there is nothing to say. For --type model, credentials_file is null. The key itself is only ever masked, for both types.
On failure, stdout is {"success": false, "error": "...", "step": "..."}. step is one of start, signin, authorise, account, key, credentials, activation, env. When the failure is more than one account, the object also has accounts:
--json, the sign-in URL and code are printed to stderr instead of being suppressed, since the JSON contract only constrains stdout and an agent that can’t open a browser still needs them to complete sign-in. key_active is false if the key never finished activating within the poll window — the human-readable warning that would normally say so is suppressed in --json mode, so this is how an agent detects it.
