# SayGM agent sign-up: instructions for an AI agent

You are helping a user get a SayGM API key with no email, no sign-up form and no credit card. You open the account with a crypto wallet signature and fund it with TAO, or with USDC once signed in. Work through the phases in order. Tell the user what you are doing at each step, and keep your messages short.

SayGM is an LLM API gateway. One key reaches Claude, GPT, Gemini and open-weight models. Inference is OpenAI-, Anthropic- and Gemini-compatible.

## Rules

- Never ask the user to paste a recovery phrase, password or private key into the chat. The user types those into `btcli` themselves.
- Never send TAO without the user confirming the exact amount first.
- Store the API key in the user's secret store or a `.env` file. Do not print it in the chat after you have saved it.
- Use one wallet for everything. The wallet that signs in must be the wallet that pays, because SayGM matches deposits to accounts by the sending address.
- Use `saygm.com`. Do not use `saygm.ai`.
- You cannot answer interactive `btcli` prompts. Settle the wallet password in Phase 2 before anything is timed, and pass `--yes` to `btcli wallet transfer`.

## Hosts

| Host | Purpose | Auth |
| --- | --- | --- |
| `https://account.saygm.com/v1` | Sign-in, API keys, balance | `Authorization: Bearer <access_token>` |
| `https://api.saygm.com/v1` | Inference | `Authorization: Bearer <gm_live_ key>` |

## Phase 1: check the environment

You need a Linux shell (Linux, macOS or WSL on Windows) with `curl` and `btcli`.

1. Run `btcli --version`. If it is missing, install it by following https://www.bittensor.com/docs/quickstart. Ask the user before installing.
2. Run `btcli wallet list` to see which wallets exist.

## Phase 2: guide the user through the wallet

### 2.1 Settle the password first

`btcli` asks for a password when it creates or imports a wallet. If the user sets one, every signature and transfer needs it, and you cannot type it. Explain this to the user **before** they create or import the wallet, and ask them to choose:

- **Option A: no password (recommended).** Use a dedicated wallet for the agent that only ever holds a few dollars of TAO. Add `--no-password` when creating or importing it. Anyone who can read the wallet file can spend from it, which is why it should hold only a small amount.
- **Option B: keep a password in a file.** The user writes the password to a file in their own terminal, so it never appears in the chat. The command is for bash; in zsh, run `bash` first:

  ```bash
  read -rsp 'Wallet password: ' P && printf '%s\n' "$P" > ~/.saygm-wallet-pw && chmod 600 ~/.saygm-wallet-pw && unset P
  ```

  Then add `--wallet-password-file ~/.saygm-wallet-pw` to every `btcli wallet sign` and `btcli wallet transfer` command. Pass the flag each time rather than exporting `BT_WALLET_PASSWORD_FILE`, because shell state may not persist between your commands. Tell the user to delete the file when you are done.

If the wallet already exists with a password, use option B.

### 2.2 Create or import the wallet

Ask the user which applies, and give them the command for their password choice. The user runs it in their own terminal.

- **They have a TAO wallet in a browser extension such as Talisman.** Import it with the recovery phrase: `btcli wallet regen-coldkey --wallet <name>` (add `--no-password` for option A). For option A, suggest creating a fresh wallet instead, so their main wallet stays encrypted.
- **They have no wallet.** `btcli wallet create --wallet <name>` (add `--no-password` for option A). They must store the recovery phrase it shows somewhere safe.
- **The wallet already exists in `btcli`.** Ask them for the name.

Get the wallet's public address with `btcli wallet list`. It starts with `5`. `btcli` calls this wallet a "coldkey".

### 2.3 Test signing before anything is timed

The sign-in nonce in Phase 4 expires after 5 minutes. Prove signing works first:

```bash
btcli wallet sign --wallet <wallet-name> --message test --json
```

Add `--wallet-password-file ~/.saygm-wallet-pw` for option B. The output must contain `signed_message` without any prompt. If the command stops at a password prompt, cancel it and go back to 2.1. Do not start Phase 4 until this test passes.

## Phase 3: make sure the wallet holds TAO

Run:

```bash
btcli wallet balance --wallet <wallet-name> --network finney
```

If the balance is zero or too low, tell the user to buy TAO on an exchange and withdraw it to the wallet address. A few dollars is enough to start. The minimum credit is $0.01 and amounts do not need to be round numbers. Wait until the user says the TAO has arrived, then check the balance again. If the user will fund the account with USDC instead (see Phase 6), signing in needs no TAO, so skip this phase.

## Phase 4: sign in and create the account

### 4.1 Ask for a challenge

```bash
ACCOUNT_API='https://account.saygm.com/v1'
ADDRESS='<wallet address>'
curl -sS --fail-with-body "$ACCOUNT_API/oauth/challenge" \
  -H 'Content-Type: application/json' \
  --data "{\"address\":\"$ADDRESS\"}"
```

The response has `nonce`, `expires_in` (300 seconds) and a ready-made `sign_command`. Finish 4.2 and 4.3 within 5 minutes.

### 4.2 Sign the nonce

```bash
NONCE='<exact nonce from 4.1>'
btcli wallet sign --wallet <wallet-name> --message "$NONCE" --json
```

- Take `signed_message` (hex) as the signature.
- Check that `signer_address` equals `ADDRESS`. If it does not, stop and tell the user.
- For option B, add `--wallet-password-file ~/.saygm-wallet-pw`, exactly as in the 2.3 test.

### 4.3 Trade the signature for tokens

This call creates the account and links the wallet for deposits. There is no separate linking step.

```bash
SIGNATURE='<signed_message from 4.2>'
curl -sS --fail-with-body "$ACCOUNT_API/oauth/token" \
  --data-urlencode 'grant_type=urn:taostats:params:oauth:grant-type:bittensor-signature' \
  --data-urlencode 'client_id=saygm-cli' \
  --data-urlencode "nonce=$NONCE" \
  --data-urlencode "address=$ADDRESS" \
  --data-urlencode "signature=$SIGNATURE" \
  --data-urlencode 'device_name=my-agent'
```

The response has `access_token` (valid 900 seconds), `refresh_token` and `session_id`. Keep both tokens.

### Refreshing the access token

The access token expires after 15 minutes. If a call returns `401 Invalid or expired token`, refresh:

```bash
curl -sS --fail-with-body "$ACCOUNT_API/oauth/token" \
  --data-urlencode 'grant_type=refresh_token' \
  --data-urlencode 'client_id=saygm-cli' \
  --data-urlencode "refresh_token=$REFRESH_TOKEN"
```

Every refresh rotates the refresh token. Store the new pair each time.

## Phase 5: create one API key

```bash
ACCESS_TOKEN='<access_token from 4.3>'
curl -sS --fail-with-body -X POST "$ACCOUNT_API/keys" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H 'Content-Type: application/json' --data '{"name":"agent"}'
```

The key is in the `secret` field and starts with `gm_live_`. It is shown only once. Save it immediately, then tell the user where you saved it.

Create only one key. When `shared_balance` is false in the `$ACCOUNT_API/balance` response, each key spends only its share of the balance, so a second key leaves the first with less. `PUT $ACCOUNT_API/keys/allocation-mode` with `{"shared":true}` lets every key spend the whole balance. To remove a spare key, call `DELETE $ACCOUNT_API/keys/<id>` with the same bearer token.

## Phase 6: fund the account

1. Confirm the amount with the user. Leave a little TAO in the wallet for the network fee.
2. Confirm the deposit address. On 11 November 2026 it was:

   `5FqbWhtCvoSD3X3iNxyWXogrKGmeVLnjZXoNWPx16yErYQd9`

   To check it is still current, request a quote and compare the `payTo` field:

   ```bash
   curl -sS -D - -o /dev/null -X POST https://saygm.com/x402/api-keys \
     -H 'Content-Type: application/json' --data '{"amount_cents":500,"key_name":"check"}' \
     | grep -i '^payment-required:' | cut -d' ' -f2 | tr -d '\r' | base64 -d
   ```

   If `accepts[0].payTo` differs from the address above, use `payTo` and tell the user.
3. Send a plain transfer from the same wallet. No memo, no swap. `--yes` skips the confirmation prompts, so only run this after the user has confirmed the amount. Add `--wallet-password-file ~/.saygm-wallet-pw` for option B.

```bash
btcli wallet transfer --wallet <wallet-name> --network finney --yes \
  --dest 5FqbWhtCvoSD3X3iNxyWXogrKGmeVLnjZXoNWPx16yErYQd9 --amount <TAO>
```

If `btcli` reports that the balance cannot cover the amount plus fees, the transaction still landed and the fee was taken. Run `btcli wallet balance` before you retry.

### Alternative: USDC on Ethereum mainnet

If the user holds USDC instead of TAO, request the account's deposit address. Repeat calls return the same address.

```bash
curl -sS --fail-with-body -X POST "$ACCOUNT_API/wallets/usdc/assign" \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

The user sends USDC on Ethereum mainnet from any EVM wallet to the returned `eth_address`. The minimum is 1 USDC. Credit appears after two block confirmations and is rounded down to whole cents. Confirm the amount with the user first, as for TAO.

## Phase 7: wait for credit

```bash
curl -sS "$ACCOUNT_API/balance" -H "Authorization: Bearer $ACCESS_TOKEN"
```

Credit appears once the transfer is final, usually within 1 to 2 minutes. The TAO is converted at the market rate at that moment and rounded down to whole cents. Deposits from the linked wallet are matched automatically, including deposits sent before sign-in. If nothing shows after a few minutes, check the balance again before sending more. Refresh the access token if you poll for longer than 15 minutes.

## Phase 8: make a test call

List models and the API shape each one uses:

```bash
API_KEY='<gm_live_ key>'
curl -sS https://api.saygm.com/v1/models -H "Authorization: Bearer $API_KEY"
```

Each model lists its `api_shapes`. Filter with `?api_shape=chat.completions`, `messages` or `generateContent`.

GPT, DeepSeek, GLM, Kimi and other open models use OpenAI Chat Completions:

```bash
curl -sS https://api.saygm.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" -H 'Content-Type: application/json' \
  --data '{"model":"deepseek-v4.1-flash","messages":[{"role":"user","content":"gm"}]}'
```

Claude models use the Anthropic Messages API. Sending a Claude ID to `/v1/chat/completions` returns `unknown model`.

```bash
curl -sS https://api.saygm.com/v1/messages \
  -H "x-api-key: $API_KEY" -H 'anthropic-version: 2023-06-01' \
  -H 'Content-Type: application/json' \
  --data '{"model":"claude-haiku-4-5","max_tokens":64,"messages":[{"role":"user","content":"gm"}]}'
```

Gemini models use `POST https://api.saygm.com/v1beta/models/{model}:generateContent`.

## Phase 9: hand over

Tell the user:

- Where the API key is stored.
- The base URL: `https://api.saygm.com/v1` for OpenAI SDKs, `https://api.saygm.com` for the Anthropic and Google GenAI SDKs.
- The current balance.
- To top up later, send more TAO from the same wallet to the same address, or USDC to the assigned Ethereum address.
- For option B, to delete the password file: `rm ~/.saygm-wallet-pw`.

## Errors

- Every OAuth error returns `error` and `error_description`. Read them before retrying.
- On `429`, wait for the number of seconds in the `Retry-After` header.
- A nonce is single use and expires after 5 minutes. On a signature error, start again from 4.1.

## Alternative: one request with x402

SayGM also sells a key in a single HTTP exchange using x402. Prefer the phases above, which have a published end-to-end test. Use x402 only if you can sign a transfer without broadcasting it.

1. `POST https://saygm.com/x402/api-keys` with `{"amount_cents": 500, "key_name": "agent"}`. The minimum is $5, in $5 steps.
2. The reply is `402` with a base64 `payment-required` header holding TAO quotes and a Sign-In-With-X challenge.
3. Sign the quoted transfer without broadcasting it, then resend the request with the `PAYMENT-SIGNATURE` and `SIGN-IN-WITH-X` headers.
4. SayGM broadcasts the payment, opens the account and returns the key.

An account that already exists can buy credit the same way: `POST https://account.saygm.com/v1/payments/x402` with the bearer access token and `{"amount_cents": 500}`. It returns the same kind of `402` quote and Sign-In-With-X challenge. If the signed resend returns `202`, settlement is pending: replay the identical request with the same signed bytes.
