API Tokens
Generate and use API tokens for direct Agnic access
API Tokens
API tokens provide direct access to Agnic APIs without the OAuth2 flow. They're ideal for scripts, CI/CD pipelines, and AI agents.
Creating a Token
- Go to your Agnic Dashboard
- Click Connect App
- Configure spending limits:
- Max per transaction: Maximum USD for a single transaction
- Daily limit: Total USD allowed per 24 hours
- Monthly limit: Total USD allowed per 30 days
- Select allowed networks (Base, Solana)
- Add an optional label
- Click Generate Token
Your token is only shown once! Save it securely.
Using Your Token
Include the token in the X-Agnic-Token header:
curl https://api.agnic.ai/api/balance \
-H "X-Agnic-Token: agnic_tok_sk_live_abc123..."Token Format
Agnic tokens follow this format:
agnic_tok_sk_live_abc123def456...| Part | Description |
|---|---|
agnic_tok | Token type identifier |
sk | Secret key indicator |
live | Environment (live/test) |
abc123... | Unique token hash |
Environment Variables
Store your token in environment variables:
# .env
AGNIC_TOKEN=agnic_tok_sk_live_abc123...import os
token = os.environ.get('AGNIC_TOKEN')Managing Tokens
List Tokens
View all your tokens in the dashboard. You can see:
- Token label
- Spending limits
- Created date
- Networks
Revoke a Token
- Go to your Dashboard
- Find the token in the list
- Click Revoke
Revoking a token is immediate and cannot be undone. Any applications using the token will stop working.
Spending Limits
Each token has three spending limits:
| Limit | Description | Resets |
|---|---|---|
| Per-transaction | Max for single transaction | Per request |
| Daily | Total per 24 hours | Rolling 24h |
| Monthly | Total per 30 days | Rolling 30d |
If a transaction would exceed any limit, the request returns a 402 error:
{
"error": "spending_limit_exceeded",
"error_description": "Daily limit exceeded",
"limit": "daily",
"current": 9.50,
"requested": 1.00,
"max": 10.00
}Best Practices
- Use descriptive labels - "Production API", "Dev Testing", etc.
- Set conservative limits - Start low, increase as needed
- Use separate tokens for different environments
- Rotate tokens periodically for long-running applications
- Never commit tokens to version control
Example: Python Script
import requests
import os
AGNIC_TOKEN = os.environ.get('AGNIC_TOKEN')
BASE_URL = 'https://api.agnic.ai'
def get_balance():
response = requests.get(
f'{BASE_URL}/api/balance',
headers={'X-Agnic-Token': AGNIC_TOKEN}
)
return response.json()
def call_ai(prompt):
response = requests.post(
f'{BASE_URL}/v1/chat/completions',
headers={
'X-Agnic-Token': AGNIC_TOKEN,
'Content-Type': 'application/json'
},
json={
'model': 'openai/gpt-4o-mini',
'messages': [{'role': 'user', 'content': prompt}]
}
)
return response.json()
# Usage
balance = get_balance()
print(f"Balance: {balance['usdcBalance']} USDC")
result = call_ai("Explain quantum computing in one sentence")
print(result['choices'][0]['message']['content'])CLI Login
You can also generate a token directly from the command line using email OTP:
npx agnic auth login [email protected]
npx agnic auth verify <flowId> <otp-from-email>The CLI stores the token locally at ~/.agnic/config.json. See the CLI reference for details.