# Environment and account setup

Use the CLI and local configuration for the selected environment. In Dev, use `openany-dev` for the commands in this guide and install or update with `npm install -g openany-cli-dev@latest`. Confirm CLI support before making network requests.

## Choose existing access or register

- **Existing account or API key.** Reuse a securely configured key, or follow the [existing API key steps](#03--existing-api-key-selected). If the account exists and needs a key, use its authorized [wallet](#wallet-login-and-api-key-management) or [email](#email-login-and-key-management) flow.
- **New account.** Follow the authorized wallet or email flow for the selected environment. New email accounts receive $0.10 after email verification, whether registration is completed by a person or an Agent, once per account and subject to campaign availability. There is no coupon, code, or manual claim. The on-chain USDC check for wallet registration is a separate verification step.
- **Registration with an invitation.** Use the exact official referral link provided by the inviter from [Dashboard → Rewards → Referral](https://openany.si/dashboard/?page=rewards&rewardsTab=referral) in the selected environment, and finish registration with the website's email or OAuth flow in that browser. Those flows carry the link's `ref` attribution into registration. Website wallet registration and current CLI registration do not support referral attribution; do not claim an invitation was bound through those paths. After registration, configure a key for that account using the existing key flow above.

After registration or key setup, [check the actual available balance and applicable key limit](./topups.md#check-the-balance). If the selected deployment publishes an authenticated account summary, use its `signupCredit` record to confirm the grant independently of the balance. Keep an unverified grant unknown and use only confirmed available balance when planning calls. [Resume the original task](./calls.md#resume-after-account-setup-or-top-up) once its access and budget checks pass.

## Email code input when no mailbox tool is available

For Seller sign-in, follow the [Seller login workflow](../openany-provider/references/login.md). For other authorized OpenAny email logins, first use an available, authorized mailbox tool. If none is connected or it cannot read the current code, open a text-input form using the host's user-input tool (for example, `request_user_input_async`). Prompt: “Enter the six-digit code sent to your OpenAny login email. It will be passed to the Agent to complete this login. Do not enter your email password.” This is an explicit exception for the current OpenAny email login code; it does not permit collecting passwords, API keys, private keys, or other credentials in forms.

Treat the response as a string, trim surrounding whitespace, and require exactly six ASCII digits; preserve leading zeros. If invalid, reopen the form without repeating the entered value. After any required browser approval, run `openany auth email verify --code SIX_DIGITS -j` with the submitted code. Do not echo the code in replies, write it to documentation, or retain it for later use. An ordinary input form returns the code to the Agent; do not describe it as a private native credential dialog. For other workflows, a local terminal is available if forms are unavailable. Do not resend merely because a mailbox tool is unavailable; reuse the current challenge, and only request a new code after expiry. A submitted form is not proof of successful login: check the CLI result.

## Log out or switch accounts

When the user requests logout or account switching, explain that this clears **all accounts in the current local configuration**, then run `openany logout -j`. First let any ongoing login, registration, or payment command finish or cancel it safely; do not start concurrent account operations. The CLI moves the complete credentials file to a uniquely named backup in the same configuration directory, retaining restricted permissions. It does not revoke server-side keys, sessions, or accounts, or cancel payments. Always show the returned `backupPath`; if null, report that no local configuration file existed. The backup contains credentials: never read it into chat, upload it, or display its contents.

Check `environmentOverrides`: if nonempty, show variable names only and ask the user to remove them from the actual calling environment before switching accounts. Do not claim complete logout while they remain. Once logout is complete, offer API Key, wallet, and email setup using a selection form when available, with text choices as fallback; use the existing setup flow for the selected method. If the user requested logout only, stop after reporting the result. Check CLI help for `logout` support and update if needed; never substitute unbacked file deletion.

## Open authorization links automatically

Whenever an authorized flow returns a browser approval or verification URL (including wallet registration and email `verificationUrl`), display the exact complete URL as a clickable link, preserving its query and `#` fragment, then immediately use an available browser-opening tool to open it visibly for the user. Do not stop at displaying the link or ask the user to open it when the tool is available. If no browser tool is available or opening fails, explain that limitation and ask the user to open the displayed link manually. Opening a page does not approve registration, login, or payment: the user must review and perform approval and human verification themselves. Keep any waiting CLI process running and continue only after the required confirmation or CLI result. This rule takes precedence over manual-link-opening wording below.

## Setup prompts

Use the format for the current stage. Preserve headings, table columns, row order, and the order of steps. Stage numbers and instructions are for the agent. Replace bracketed fields with observed results. Run only the checks needed for this task. Mark skipped checks “Not checked (reason).” If `OPENANY_CONFIG_DIR` is set, use the known configuration path without opening the credentials file.

### 01 | CLI missing or update required

Show the status table from 02, then the following prompt. When the CLI is missing, mark dependent checks as not checked.

Open a terminal on the same machine and under the same account where OpenAny runs. Install or update the CLI:

```bash
npm install -g openany-cli@latest --registry=https://registry.npmjs.org/
```

Use the install command for the selected environment. After installation or update, I will check the CLI and Node.js versions, then verify the settings needed for this task.

### 02 | Check configuration or report a missing API key

## Current status

| Check | Result | Purpose / available operations |
| --- | --- | --- |
| `openany --version` | [CLI version or installation status] (Node.js [actual version and compatibility], requires ≥22) | Verify the runtime. Public catalog browsing and model request previews require no login or API key. |
| Wallet connection | [User-facing status, as described below] | Sign in with a wallet and create or rotate keys. Top-ups also require login and payment authorization. |
| Email login | [User-facing status] | Sign in with an email verification code, select a workspace, and manage keys. |
| API key check | [User-facing status] | A valid key enables balance queries, model and API calls, and call-record queries. |

Fill in each result from the actual check:

- For a successful check, interpret `configured` and `missing` locally. If `OPENANY_API_KEY` is missing, display “API key not configured yet (`NO_APIKEY`).” For incomplete wallet or email settings, use “Wallet login not configured” or “Email login not configured.” Otherwise show “Configured” when verified. Omit booleans, lists of environment variables, and error icons for normal configuration states.
- For skipped checks, give the reason, such as “Not checked (wallet login is unnecessary for this task).” Use “Check failed” only for an actual command error. Preserve the error code and request ID.
- Give the next step relevant to the task. If the user chooses to use an existing API key, follow stage 03 and open the native dialog when supported. For public browsing, continue directly.

When configuration is missing and the user has not chosen whether to sign in or use an existing API key, first show the status table, then prefer the selection-form tool available in the current agent environment. Use the title “Choose how to access OpenAny” with three single-choice options: “Existing API key,” “Wallet login,” and “Email login.” Wait for the user to submit a choice before starting the corresponding flow.

If the environment has no available selection-form tool, show text options: “Choose how to access OpenAny: 1. Existing API key  2. Wallet login  3. Email login. Reply with a number or option name.”

If the user has already chosen an access method, proceed directly with that flow. A preselected form option does not count as user confirmation.

### 03 | Existing API key selected

On macOS and Windows desktops, open the independent native API key dialog from the agent’s command tool. Run `openany setup --api_key api_key --gui -j` and wait for the user to enter the label and the key. The CLI activates the saved key. Input travels directly to the local CLI through a private process pipe. Only configuration results reach the agent. Never read, screenshot, or automate the credential field after handing it to the user.

A `saved: true` result confirms local storage. Continue to stage 06 after the command returns and resume the pending task once configuration is verified. Cancellation or the five-minute timeout saves nothing. Pause the flow if either occurs. If `--gui` is unavailable, update the CLI and check help. Use terminal setup only if the CLI cannot open the dialog in the user’s desktop session after updating, or if the environment has no supported desktop. Environment variables still override local settings. `--gui -j` explicitly opens a dialog and saves even without a TTY.

For terminal fallback only, ask the user to run this on the machine and account where OpenAny runs:

```bash
openany setup --api_key api_key
```

Enter a key name, enter the API key at the hidden prompt, then enter `y` to make it the current key.

Configuration is saved locally to `~/.config/openany/credentials.json` with directory permissions 0700 and file permissions 0600. Never send API keys, wallet private keys, seed phrases, passwords, tokens, cookies, or credentials files in AI chats, screenshots, or attachments.

When finished, reply **Configured**. I will verify the settings and explain the next step. Setup only saves configuration. It does not sign you in or authorize payment.

### 04 | Wallet login selected

On macOS and Windows desktops, run `openany setup --wallet_connect wallet --gui -j` to open the independent wallet dialog. The user enters a stable Agent ID and private key, then confirms the locally derived wallet address in a second dialog before saving. Use the authorized external signer flow when one has already been selected. The agent receives only configuration status. Never read, screenshot, or automate the credential field after handing it to the user.

Use the cancellation, timeout, and fallback rules in section 03. When native UI is unavailable, follow the terminal instructions below.

In your own terminal on the machine where OpenAny runs, execute:

```bash
openany setup --wallet_connect wallet
```

1. Enter your **wallet private key** at the hidden prompt. EVM uses a 32-byte hexadecimal key, optionally prefixed with `0x`. Solana uses a Base58-encoded 64-byte secret key. The CLI derives and displays the address.
2. Enter a **stable Agent ID** of 6–128 letters, digits, periods, underscores, colons, or hyphens, such as `agent-main`. Record and reuse the same ID.

Configuration is saved locally to `~/.config/openany/credentials.json` with directory permissions 0700 and file permissions 0600.

When finished, reply **Configured**. I will check the settings. A new wallet holding more than 10 official USDC on Base or Solana mainnet can qualify for automatic registration verification. At 10 USDC or less, or if the balance is unavailable, I will share a required browser verification link. You can register without adding funds by passing the browser checks. Setup does not sign you in, create keys, or authorize payments.

Never send API keys, wallet private keys, seed phrases, passwords, access or refresh tokens, cookies, or credentials files in AI chats, screenshots, or attachments.

### 05 | Email configuration missing

Prefer the text-input form available in the current agent environment. Use the title “Enter your OpenAny login email address” and request only the address. An email address may be supplied through a form or chat. Reuse an address the user has already explicitly designated. If no form tool is available, ask for the address in chat.

Check the submitted address format and ask the user to correct it if needed. The agent may run the following command in an interactive terminal in the CLI's execution environment, enter the submitted address when prompted, and press Enter to save it:

```bash
openany setup --email_login email
```

Wait for saving to succeed, then run `openany status_check email -j` to verify configuration. Continue within the user's existing login authorization. Form submission supplies an address. Confirm saving and login separately from actual CLI results.

If the agent cannot operate an interactive terminal, ask the user to run the command on the same machine and account where OpenAny runs, enter the address, press Enter, and reply **Configured**. Then recheck configuration. Non-interactive mode and `-j` only check settings and cannot save the address.

Configuration is stored locally at `~/.config/openany/credentials.json` with directory permissions 0700 and file permissions 0600. This setup step saves the email address. Sending a verification code, signing in, and making payments follow their respective workflows and authorization.

The email form collects only the address. Never request passwords, API keys, wallet private keys, seed phrases, access or refresh tokens, cookies, or credentials files through forms, AI chats, screenshots, or attachments.

### 06 | Recheck after the user confirms setup

Repeat the relevant check in the CLI's actual execution environment. Fill the Current status table from 02 with fresh results, preserving its columns and row order. If further action is needed, append:

## Check conclusion

> [Repeat the status, for example “API key not configured yet (`NO_APIKEY`).”] Confirm that you configured the environment where OpenAny runs, then complete [next local action]. Do not send setting values or credentials files.

If the command itself failed, start with “Check failed: [actual error]” and include any error code and request ID. If environment overrides are reported, add: “Environment variables take precedence over local settings. Current overrides: [variable names]. Check them in the execution environment without sending their values.”

### 07 | Login or configuration verified

OpenAny [completed access method] is complete and verified.

| Item | Result |
| --- | --- |
| Wallet configuration | ✅ `configured: true`, nothing missing |
| Wallet login session | ✅ Saved [include actual expiration and remaining validity only when known] |
| API call configuration (call) | ✅ `configured: true`, balance access verified with [actual key source] |
| Account wallet address | [Actual address] |
| Agent ID | [Actual Agent ID] |
| Key ID | [Actual key ID and verified activation status] |
| Balance | **[Returned availableUsdFormatted]** |

Include only applicable, verified rows in their original order. For email login, replace the first two rows with “Email configuration” and “Email login session.” For API key setup, verify with `openany status_check api_key -j` and `openany balance -j`, then show the call configuration, key ID if known, and balance. For login alone, show only verified login information.

Include the following **Usage example** after the verified status and balance. Translate it into the user’s language. It describes the workflow without running a new API call. Follow the [balance rules](./topups.md#check-the-balance) when displaying amounts.

> To look up the Bitcoin price, start by searching for `bitcoin`. If no relevant API appears, try browsing the Finance or Crypto & DeFi category. Select a relevant data platform, such as BlockRun if listed, then carefully review the API description before calling it.

#### What would you like to do next?

1. **Top up my balance** — Learn how to fund this account and check the fee and net credit before paying.
2. **See a usage example** — Try a free example: “Use OpenAny to tell me the BTC price.”
3. **Browse API categories** — See which API services are available.
4. **List models** — See which models you can call.
5. **Explore a use case** — Show me an example of how to use an API.

Reply with a number, an option name, or a description of your task.

<!-- Agent instructions: If setup or login is part of an already requested task, continue that task. Otherwise show the menu after the success summary. -->

For option 1, follow [the top-up method selection](./topups.md#choose-a-top-up-method). For option 2, demonstrate a public catalog query using the [calling guide](./calls.md). For option 5, present one use case from the [OpenAny guides](https://openany.si/guides) and direct the user there for more. These routing instructions are for the agent.

## Wallet Login and API Key Management

After completing configuration for scenario C, choose the flow for the configured wallet. Use `openany keys list -j` to inspect local labels and metadata, together with the user's confirmed account/key information. An unrelated key, an imported key without wallet metadata, or an environment override does not establish that a key belongs to this wallet. An empty local list does not prove the wallet has never registered; ask if its account/key history is unclear.

**First-time wallet without a key.** After the user authorizes registration and key creation, start one request:

```bash
openany keys create --identity wallet --label agent-main -j
```

The backend verifies the signature and checks the signing wallet's official USDC on Base mainnet for EVM addresses or Solana mainnet for Solana addresses. This uses on-chain funds; the OpenAny API credit balance shown by `openany balance` is separate.

- **More than 10 USDC:** the wallet can register directly. Wait for the CLI to confirm that the key was saved.
- **10 USDC or less, including exactly 10 USDC:** share the required browser verification link. The user can register without funding the wallet by passing Turnstile and the browser fingerprint check.
- **Balance lookup unavailable:** explain that OpenAny could not read the balance. Use the same browser approval flow; the wallet's balance is unknown.

When approval is required, keep the original CLI command running. Even with `-j`, the reason and one-time URL appear on stderr while the command waits. If you run the CLI for the user, promptly show them that exact link, including its fragment. Ask them to open it in their browser, check the wallet address and Agent ID, and select **Verify agent registration**. The browser runs the Turnstile and encrypted fingerprint checks. The CLI polls with the original signature and saves the key after registration succeeds. Wallet-registration credits, where offered, follow the separate wallet verification rules. Check the actual grant record; do not apply the email-registration offer to an unverified wallet flow. A failed or uncompleted browser check prevents Agent registration. If the CLI reports `AUTHORIZATION_EXPIRED`, start a fresh request with the same wallet and Agent ID. For an uncertain submission, follow **Errors and Recovery** before retrying.

Only after the CLI confirms the key is saved, log in:

```bash
openany auth wallet -j
```

**Existing key for this wallet:** reuse the key and log in directly:

```bash
openany auth wallet -j
```

Do not create or rotate a key just to log in. Keep the configured wallet and stable Agent ID unchanged. Do not treat a login failure or generic 401 as proof that the wallet is unregistered. If key creation returns a recovery file, follow Errors and Recovery before login; if the outcome is uncertain, resolve it before creating again. Do not change the label or Agent ID to bypass an existing-key conflict.

Key rotation is a separate, explicitly authorized operation:

```bash
openany keys rotate --identity wallet --label agent-next --expected-key-id CURRENT_KEY_ID -j
```

The CLI retrieves the message to sign, validates the service domain, identity, operation, and expiration, then signs it. Preserve the full original title and body of the signing message returned by the service. After saving a new key, the command outputs only metadata.

When using an external signing tool, add `--prepare` to the commands above to obtain the message to sign. Sign it with an authorized tool, then submit it using the same command with `--challenge-id ID --signature-file FILE`. The signature file must contain the raw signature text and correspond to the challenge ID just retrieved.

Rotation invalidates the old key; perform it only with the user's explicit authorization. Before rotating, identify applications using the key and prepare to update their secrets. If `OPENANY_API_KEY` still contains the old value, it takes precedence over the newly saved CLI key, so update the environment and verify it as well. If the outcome is unclear, verify the state before deciding what to do next.

## Email Login and Key Management

```bash
openany auth email send -j
openany auth email verify --code SIX_DIGITS -j
openany auth email workspace --workspace WORKSPACE_ID -j
openany auth email refresh -j
openany keys remote list --limit 100 --offset 0 -j
openany keys remote create --label agent-main -j
openany keys remote get --id KEY_ID -j
openany keys remote revoke --id KEY_ID -j
```

**Email sign-in and new-account registration:** Read the configured email address and run `openany auth email send -j` once. This sends the six-digit email code before the registration branch:

- **New email (`registrationRequired: true`):** Immediately display the exact returned `verificationUrl` as a clickable browser link, including its full `#` fragment. The CLI also prints this link to stderr, including in JSON mode. Tell the user to open it, check the email address, and complete **Turnstile** themselves. Wait for their confirmation before verifying the email code; do not solve the challenge on their behalf. Browser approval alone does not register or log in: the same request must also pass email-code verification.
- **Existing account (no registration requirement):** Continue directly to email-code verification; do not request browser Turnstile.
- After browser approval when required, obtain the current six-digit code through the authorized mailbox flow below and run `openany auth email verify --code SIX_DIGITS -j`. Preserve leading zeros. Only a successful verify response completes registration/login; then select a workspace if required.
- If verify returns `HUMAN_VERIFICATION_REQUIRED`, ask the user to finish the already-issued browser link and retry verification for the same challenge after confirmation. Do not repeatedly send new codes. If the challenge expires, request a fresh code and, for a new email, present its new link; resending invalidates the previous link and code. A missing or invalid required link is an error: do not invent a URL or skip human verification.

Use the Seller login workflow above for Seller sign-in. For other email logins, read the current verification code through an authorized email connection, preserving all six digits and any leading zeros. If the email connection is unavailable, collect the current code using the email-code input form described above; use terminal verification only when forms are unavailable. Do not send another code just because mailbox access is unavailable; only request a fresh challenge after expiry and repeat its required browser verification. Never request the mailbox password. Use the dedicated form for the current login code and do not repeat its value. Avoid sending codes repeatedly. A single workspace is selected automatically; if there are multiple workspaces, select the one authorized by the user. Relevant commands also accept `--workspace ID`.

The CLI saves email login state but does not automatically refresh it. For an expired email session, explicitly run `openany auth email refresh -j`; if refresh is denied, log in again through the authorized mailbox. If refresh has an uncertain outcome or returns a recovery file, follow the recovery error before retrying. Refreshing an email session does not repair an invalid API key. Remote key lists use `limit/offset` pagination. Updating an email-based key requires separate steps: create a new key → update applications using it → verify the new key → revoke the specified old key within the user's authorization. Keep the old key until verification is complete to avoid disrupting existing calls.

## Errors and Recovery

If the CLI returns `REGISTRATION_IP_LIMITED` during wallet or email registration, immediately tell the user that the current IP address has reached the registration limit and stop the current operation. Do not retry, wait and retry, or switch the registration method or network within this operation, even if a retry time is provided.

For model or API provider failures, supported CLI versions retain the platform's bounded recovery and candidate fields in ordinary and `-j` errors, including v2 compatibility levels and missing evidence. Follow [recovery after provider failures](./calls.md#recovering-after-provider-failures): first inspect the current target contract, then prepare any suitable request within the task's authorization and budget. `needs_inspection` permits reading details only; unknown pricing does not mean free. Candidates do not authorize a new charge, registration or top-up, or prove that an uncertain original request did not execute.

On failure, the CLI returns a nonzero exit code and writes `{"error":{"code":"...","message":"..."}}` to standard error (stderr), possibly including `requestId`, `status`, and `missing`. Explain the error to the user and retain the error code and request ID without exposing credentials. Judge success by the final business outcome; HTTP 200, heartbeats, or the start of a stream indicate only request progress.

If login or key management succeeds on the server but cannot be saved locally, the CLI returns the path to a recovery file with restricted access. Use `openany auth recover --file RETURNED_PATH` to recover the original result and avoid creating duplicate keys; import only verified recovery files. For other unclear outcomes, follow the error guidance. If the configuration lock is held, first check whether the associated process is still running. If the process has exited but the lock remains, ask a maintainer to help clear the specified lock; do not automatically delete locks or retry payments.

A balance query verifies only the current key's ability to access the balance. It does not verify wallet signing, email connectivity, or payment permissions. If a required capability is missing, explain exactly what is missing and the next configuration steps. Report task completion based on actual execution results.
