AgentKit
DocsKitsCLI ReferenceDesktop App

CLI Reference

ak login

Authenticate to the AgentKit registry with a license key, email OTP, or user API key while keeping credential storage boundaries explicit.

Use ak login before installing or updating a licensed remote kit. You must select one authentication method; bare ak login is not an interactive method picker.

Usage

ak login [flags]

The documented command has no positional arguments. The current implementation ignores extra positional tokens, so do not use that behavior in scripts.

Before you run

Choose one method:

printf '%s' "$AK_KEY" | ak login --api-key-stdin
AGENTKIT_API_KEY=ak_live_... ak login
ak login --email you@example.com
ak login --license-key ak_license_... --no-interactive

Use placeholders in saved scripts and support output. A successful result never prints the API key, license key, OTP, access token, or refresh credential.

For scripted login, pipe the API key to --api-key-stdin or set AGENTKIT_API_KEY; both keep the key out of the process argument list. --api-key still works but exposes the key to other local users and process monitors, so it prints a warning on stderr (warning: --api-key puts the key in the process argument list ...); with --json the warning is carried in data.warnings[] instead. AGENTKIT_API_KEY is read only when no sign-in flag is given. --api-key-stdin reads a piped key, not terminal input: a TTY on stdin, an empty key, a key containing whitespace, or an oversized input exits 2 before contacting the registry.

API key vs. license key

--api-key is for Kit owners: it authenticates the CLI with a user API key tied to a purchased, team, or paid-waitlist Kit grant. --license-key is for the AgentKit App: it activates a device session from an App license and does not by itself grant CLI access to a Kit. An account can hold either, both, or neither; verify with ak whoami --json and ak licenses --json, and see Authentication troubleshooting for the specific rejection errors.

Email login is interactive-only. It needs a terminal on both stdin and stdout, and it refuses to start with --yes, --json, --no-interactive, or --quiet. In those cases it exits 2 before contacting the registry and points you to --api-key-stdin or AGENTKIT_API_KEY, the methods for scripts and CI.

When the code does not arrive

The registry answers the same way for an unknown email and for one with a purchase, so ak login --email cannot tell you that an address has no purchase. Before the code prompt it prints on stderr:

If you@example.com has an AgentKit purchase, a code was emailed to it (usually within a minute).
No email? Check spam, and make sure the address exactly matches the one you purchased with; rerun `ak login --email <email>` to fix a typo.

Pressing Enter or Ctrl-D without a code fails with login: no code entered., and a rejected code fails with login: code is invalid or expired.. Both messages add the same guidance: check the spelling, rerun ak login --email <email>, or sign in at https://agentkit.best to confirm your account email. See Authentication troubleshooting.

Options

FlagDefaultDescription
--api-key <key>EmptyAuthenticate with a user API key from your web profile. The key is visible in the process list; prefer --api-key-stdin or AGENTKIT_API_KEY.
--api-key-stdinfalseRead the user API key from standard input.
--device-name <name>HostnameName the device created by --license-key.
--email <address>EmptyStart email OTP login in an interactive terminal, then read the code from stdin.
--license-key <key>EmptyActivate a license-key App device session.
--registry-url <url>Environment or release defaultOverride the registry used for authentication and later session checks.

Shared flags are described in CLI conventions. --yes has no effect on this command. If several method flags are supplied, the current precedence is license key, then API key, then email; pass exactly one. --api-key-stdin combined with --api-key or --license-key exits 2.

Credential storage

After the registry accepts the credential, AgentKit writes private files under ~/.agentkit/auth/ (AGENTKIT_HOME changes the base directory):

MethodStored slotRenewable secret retained locally
API keyCLI slot in session.jsonThe API key in the sibling api-key file, for session re-minting.
Email OTPCLI slot in session.jsonA rotating refresh credential; the one-time OTP is not stored.
License keyApp slot in session.jsonThe returned device session; the license key is not stored.

Credential writes are atomic, use private path protection, and refuse to write through a credential-file symlink. CLI and App slots can coexist; logging in to the CLI slot does not replace an existing App device session.

Output and streams

Human success output is written to stdout:

[OK] logged in as you@example.com

JSON success is one versioned envelope on stdout:

{"schema_version":1,"kind":"auth.login","data":{"email":"you@example.com","authMethod":"api_key","success":true}}

data.warnings[] appears only when there is an attention item, such as the --api-key exposure warning.

Runtime and authentication errors use stderr. JSON-mode failures, including flag-parse errors (exit 2), end stderr with the shared error envelope.

Exit status

ExitMeaningSafe next step
0Registry authentication succeeded and the selected local slot was saved.Run ak whoami and ak licenses.
1No method was selected, no OTP code was entered, the code was invalid or expired, the registry rejected the request, the response was incomplete, or private storage failed.Correct the method or credential, then retry; do not publish the secret in logs.
2A flag could not be parsed, email login was started without an interactive terminal or with --yes, --json, --no-interactive, or --quiet, --api-key-stdin was combined with --api-key or --license-key, or the stdin key was read from a TTY, empty, malformed, or too large.Correct the invocation; pipe the key to --api-key-stdin or set AGENTKIT_API_KEY for scripted login.

There is no preview, dry-run, confirmation, or decline path. Storage occurs only after the remote login response validates. Re-running login replaces the selected slot; use ak logout to clear the CLI slot.