Set up the authentication for your API to help users manage their credentials.
| API Key | Label | Last Used | |
|---|---|---|---|
Authenticate all Astra API requests by including your API key in the request header.
Astra supports two authentication methods:
- API Keys — For server-side integrations you control. Pass
sk_live_...as a Bearer token. - OAuth 2.0 — For third-party integrations that act on behalf of an Astra user. Uses the Authorization Code flow to obtain
astra_at_...access tokens.
Get your API key
Create an API key from the Astra Dashboard:
- Log in to the Astra Dashboard.
- Navigate to Account → API Keys.
- Click Create API Key.
- Copy and store the key immediately.
Your API key (starting with
sk_live_) is displayed only once at creation time. It cannot be retrieved later — store it somewhere safe before closing the dialog.
Authenticate requests
Include your API key in the Authorization header as a Bearer token:
Authorization: Bearer sk_live_your_api_key_here
Alternatively, pass it via the X-API-Key header:
X-API-Key: sk_live_your_api_key_here
curl -X GET https://astra-gateway.wati.io/v1/agents \
-H "Authorization: Bearer sk_live_your_api_key_here"import requests
API_KEY = "sk_live_your_api_key_here"
response = requests.get(
"https://astra-gateway.wati.io/v1/agents",
headers={"Authorization": f"Bearer {API_KEY}"}
)
if response.status_code == 200:
agents = response.json()
print(agents)
elif response.status_code == 401:
print("Authentication failed — check your API key")
else:
print(f"Request failed with status {response.status_code}: {response.text}")const API_KEY = "sk_live_your_api_key_here";
const response = await fetch("https://astra-gateway.wati.io/v1/agents", {
headers: { Authorization: `Bearer ${API_KEY}` },
});
if (response.ok) {
const agents = await response.json();
console.log(agents);
} else if (response.status === 401) {
console.error("Authentication failed — check your API key");
} else {
console.error(`Request failed with status ${response.status}`);
}A successful request returns a 200 status code with the response body. An invalid or missing key returns a 401:
{
"error": {
"code": "unauthorized",
"message": "Invalid or missing API key"
}
}OAuth 2.0
For third-party integrations that need to act on behalf of an Astra user, use the OAuth 2.0 Authorization Code flow. After obtaining an access token, include it in the Authorization header the same way as an API key:
Authorization: Bearer astra_at_your_access_token_here
Flow overview
- Register an OAuth app — Call
POST /oauth/appsfrom the Dashboard (requires session auth) to get aclient_idandclient_secret. - Redirect the user — Send the user to your consent page with
client_id,redirect_uri,scope, andstateparameters. - User approves — After approval,
POST /oauth/authorizereturns a redirect URI containing an authorizationcode. - Exchange the code — Call
POST /oauth/tokenwithgrant_type: authorization_codeto receive an access token and refresh token. - Make API requests — Use the access token (
astra_at_...) as a Bearer token. - Refresh when expired — Call
POST /oauth/tokenwithgrant_type: refresh_tokento get a new token pair.
Token lifetimes
| Token | Prefix | Validity |
|---|---|---|
| Access token | astra_at_ | 24 hours |
| Refresh token | astra_rt_ | 30 days |
Register an OAuth app
curl -X POST https://astra-gateway.wati.io/v1/oauth/apps \
-H "Authorization: Bearer $SESSION_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "My Integration",
"redirect_uris": ["https://myapp.example.com/callback"],
"scopes": ["chat", "agents:read", "agents:write"]
}'{
"app": {
"id": "a1b2c3d4-...",
"name": "My Integration",
"client_id": "oapp_abc123",
"redirect_uris": ["https://myapp.example.com/callback"],
"scopes": ["chat", "agents:read", "agents:write"],
"is_active": true
},
"client_secret": "osec_xyz789..."
}The
client_secretis displayed only once at creation time. Store it securely before closing the response.
Exchange code for tokens
curl -X POST https://astra-gateway.wati.io/v1/oauth/token \
-H "Content-Type: application/json" \
-d '{
"grant_type": "authorization_code",
"code": "auth_code_from_redirect",
"client_id": "oapp_abc123",
"client_secret": "osec_xyz789...",
"redirect_uri": "https://myapp.example.com/callback"
}'{
"access_token": "astra_at_abc123...",
"refresh_token": "astra_rt_def456...",
"token_type": "Bearer",
"expires_in": 86400,
"scope": "chat agents:read agents:write"
}Refresh an access token
curl -X POST https://astra-gateway.wati.io/v1/oauth/token \
-H "Content-Type: application/json" \
-d '{
"grant_type": "refresh_token",
"refresh_token": "astra_rt_def456...",
"client_id": "oapp_abc123",
"client_secret": "osec_xyz789..."
}'OAuth scopes
OAuth apps can request any combination of the following scopes:
| Scope | Description |
|---|---|
* | Full access to all resources |
chat | Send messages and interact with agents |
agents:read | Read agent configurations |
agents:write | Create and update agents |
conversations:read | Read conversation history |
conversations:write | Create conversations |
contacts:read | Read contacts |
contacts:write | Create and update contacts |
knowledge:read | Read knowledge bases |
knowledge:write | Manage knowledge bases |
webhooks:manage | Manage webhook subscriptions |
analytics:read | Read analytics data |
actions:read | Read configured actions |
actions:write | Manage actions |
connections:read | Read platform connections |
connections:write | Manage connections |
files:read | Read uploaded files |
files:write | Upload and manage files |
voice:read | Read voice configurations |
voice:write | Manage voice settings |
templates:read | Read agent templates |
API key scopes
Each API key has scopes that control which endpoints it can access. Assign only the scopes your integration needs.
| Scope | Description |
|---|---|
all | Full access to all endpoints |
chat | Send and receive messages |
agents:read | List and retrieve agents |
agents:write | Create, update, and delete agents |
conversations:read | List and retrieve conversations |
contacts:read | List and retrieve contacts |
contacts:write | Create, update, and delete contacts |
knowledge:read | List and retrieve knowledge bases and documents |
knowledge:write | Create, update, and delete knowledge bases and documents |
analytics:read | Access analytics and performance metrics |
webhooks:manage | Create, update, and delete webhooks |
Security best practices
Astra enforces several security measures for API keys:
- Hashed storage — Keys are hashed with HMAC-SHA256 before storage. The raw key cannot be recovered from the database.
- Single display — The full key is shown only once at creation. There is no endpoint to retrieve it again.
- Tenant isolation — Each key is bound to a
tenant_id. Requests cannot access other tenants' data. - Immediate revocation — Revoked keys are rejected on the next request with no delay.
Follow these practices to keep your keys secure:
- Store keys in environment variables — never hardcode them in source files.
export ASTRA_API_KEY="sk_live_your_api_key_here" - Never commit keys to version control. Add your
.envfile to.gitignore. - Rotate keys periodically using the rotate endpoint, even if you don't suspect a leak.
- Use the minimum scopes required for each integration. Avoid using
allunless necessary.
Key management
Manage your API keys programmatically after creating them in the Dashboard.
Rotate a key
Replace a key with a new one in a single atomic operation. The old key is invalidated immediately and a new key is returned with the same name and scopes.
curl -X POST https://astra-gateway.wati.io/v1/api-keys/{key_id}/rotate \
-H "Authorization: Bearer $SESSION_TOKEN"Revoke a key
Permanently disable a key. Revoked keys cannot be reactivated.
curl -X DELETE https://astra-gateway.wati.io/v1/api-keys/{key_id} \
-H "Authorization: Bearer $SESSION_TOKEN"List keys
Retrieve all API keys for your account. The response includes metadata (name, scopes, request count, last used) but not the raw key values.
curl -X GET https://astra-gateway.wati.io/v1/api-keys \
-H "Authorization: Bearer $SESSION_TOKEN"Key management endpoints (
/v1/api-keys) require a valid Dashboard session token, not an API key. You must be logged into the Astra Dashboard to create, rotate, revoke, or list keys.
Rate limiting
API requests are rate-limited per key at 10 requests per second with a burst allowance of 20 requests.
When you exceed the limit, the API returns a 429 Too Many Requests response with a Retry-After header indicating how many seconds to wait:
{
"error": {
"code": "rate_limited",
"message": "Too many requests"
}
}Handle rate limits by respecting the Retry-After header:
import time
import requests
def make_request(url, headers):
response = requests.get(url, headers=headers)
if response.status_code == 429:
retry_after = int(response.headers.get("Retry-After", 1))
print(f"Rate limited — retrying in {retry_after}s")
time.sleep(retry_after)
return make_request(url, headers) # Retry once
return responseasync function makeRequest(url, headers) {
const response = await fetch(url, { headers });
if (response.status === 429) {
const retryAfter = parseInt(response.headers.get("Retry-After") || "1", 10);
console.log(`Rate limited — retrying in ${retryAfter}s`);
await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000));
return makeRequest(url, headers); // Retry once
}
return response;
}Request tracing
Every API response includes an X-Request-Id header. You can also pass your own request ID via the same header. Include this ID when contacting support for faster debugging.
Troubleshooting
401 Unauthorized — Invalid or missing API key
- Confirm the key starts with
sk_live_and is complete (no trailing whitespace or truncation). - Check the header format:
Authorization: Bearer sk_live_...(note the space afterBearer). - Verify the key hasn't been revoked in Settings → API Keys in the Dashboard.
403 Forbidden — Insufficient scopes
The key is valid but doesn't have the required scope for this endpoint. Check the key's assigned scopes in the Dashboard and add the missing scope, or create a new key with the correct scopes.
429 Too Many Requests — Rate limit exceeded
You're sending more than 10 requests per second. Add retry logic that reads the Retry-After header, or reduce request frequency. If you consistently need higher throughput, contact support.
Key lost — Cannot retrieve API key
API keys are shown only once at creation. If you've lost a key, revoke it in the Dashboard and create a new one. Update all integrations with the new key.
