> ## Documentation Index
> Fetch the complete documentation index at: https://sdk.avantisfi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Delegates & API Keys

> Register trading keys that can never touch your funds.

A delegate (API key) is a separate key registered to your wallet. It signs orders on your behalf; the wallet keeps the funds. This is the recommended setup for bots and agents.

|                                           | Trader key | Delegate / API key     |
| ----------------------------------------- | ---------- | ---------------------- |
| Trade (open/close/TP/SL/margin/TWAP)      | Yes        | Yes                    |
| Withdraw funds, approve USDC              | Yes        | **No**                 |
| Add/remove delegates                      | Yes        | **No**                 |
| Referral, claims, LP vault, builder codes | Yes        | **No** (caller-scoped) |

The SDK enters delegate mode automatically when `AVANTIS_PRIVATE_KEY`'s address differs from `AVANTIS_TRADER_ADDRESS`.

## Easiest path: the API Key Generator

Generate an API key on the [Avantis API Key Generator](https://delegate.avantisfi.com/); one wallet signature registers it. Then set the two env vars and trade. See [Quickstart](/quickstart).

## DIY registration

Register any key programmatically. The trader key signs one `DelegateReq` intent (used transiently, never stored); submission is gasless:

```python theme={null}
import time
from avantis_trader_sdk import AsyncAvantis, LocalSigner

async with AsyncAvantis(private_key=DELEGATE_KEY, trader_address=WALLET) as client:
    await client.account.register_delegate(
        delegate=LocalSigner(DELEGATE_KEY).address,
        expiry_seconds=int(time.time()) + 60 * 60 * 24 * 90,  # ABSOLUTE unix ts, in seconds
        trader_signer=LocalSigner(WALLET_KEY),   # transient, one signature
    )
```

<Warning>
  `expiry_seconds` is an **absolute** unix timestamp in seconds (not a
  duration, not milliseconds). The API rejects anything that isn't a future
  timestamp.
</Warning>

Registration is gasless and needs no RPC: it rides the fresh delegate key's
EIP-7702 smart account. Relayer mode only needs an `rpc_url` when you run
the SDK with your **wallet key** as the signer; see
[Execution modes](/advanced/execution-modes).

## Check and verify

```python theme={null}
status = await client.account.delegation_status()
# {"isEnabled": True, "expiry": ..., "canDelegatedAction": ..., "canSignIntents": ...}

await client.account.verify_delegation()   # raises DelegationError if the key can't act
```

Call `verify_delegation()` at startup for a fail-fast bot: it is a no-op when the signer is the trader itself.

## Revoke

```python theme={null}
await client.account.revoke_delegate(delegate_address)   # trader key only
```

Revoking kills any in-flight intents signed by that delegate. You can also revoke from the UI.
