Agent Studio

Authentication

Authentication methods for the Agent Studio API

Authentication

Agent Studio supports two authentication methods to accommodate different use cases.

Authentication Methods

MethodUse CaseToken Lifetime
JWT BearerUser sessions, dashboard30 min access, 7 day refresh
API KeyServer-to-server, integrationsNo expiry (until revoked)

JWT Authentication

JWT (JSON Web Token) authentication is used for user sessions, typically from the dashboard or mobile apps.

Obtaining Tokens

POST /api/v1/auth/login
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "your-password"
}

Response:

{
  "access_token": "eyJhbGciOiJIUzI1NiIs...",
  "refresh_token": "eyJhbGciOiJIUzI1NiIs...",
  "token_type": "bearer",
  "expires_in": 1800
}

Using Access Tokens

Include the access token in the Authorization header:

GET /api/v1/agents
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...

Refreshing Tokens

Access tokens expire after 30 minutes. Use the refresh token to get a new access token:

POST /api/v1/auth/refresh
Content-Type: application/json

{
  "refresh_token": "eyJhbGciOiJIUzI1NiIs..."
}

Response:

{
  "access_token": "eyJhbGciOiJIUzI1NiIs...",
  "refresh_token": "eyJhbGciOiJIUzI1NiIs...",
  "token_type": "bearer",
  "expires_in": 1800
}

Token Payload

JWT tokens contain the following claims:

{
  "sub": "user-uuid",
  "tenant_id": "tenant-uuid",
  "type": "access",
  "scopes": ["agents:read", "agents:write"],
  "exp": 1705488600,
  "iat": 1705486800
}

API Key Authentication

API keys are used for server-to-server communication, webhooks, and automated integrations.

Key Formats

API keys are prefixed for easy identification:

PrefixEnvironmentUse
as_live_ProductionLive data and calls
as_test_TestingSandbox/staging

Example: as_live_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6

Creating API Keys

POST /api/v1/auth/api-keys
Authorization: Bearer <access_token>
Content-Type: application/json

{
  "name": "Production Integration",
  "environment": "live",
  "scopes": ["agents:read", "workflows:*", "calls:*"],
  "rate_limit": 500
}

Response:

{
  "key": "as_live_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
  "id": "key-uuid",
  "name": "Production Integration",
  "environment": "live",
  "scopes": ["agents:read", "workflows:*", "calls:*"],
  "rate_limit": 500,
  "created_at": "2026-01-17T10:30:00Z"
}

Security Note: The full API key is only returned once during creation. Store it securely - you cannot retrieve it again.

Using API Keys

Include the API key in the X-API-Key header:

GET /api/v1/agents
X-API-Key: as_live_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6

Managing API Keys

List Keys:

GET /api/v1/auth/api-keys

Revoke a Key:

DELETE /api/v1/auth/api-keys/{id}

Permission Scopes

Scopes control what resources an authenticated request can access.

Available Scopes

ScopeDescription
*Full access (admin)
agents:readRead agents
agents:writeCreate/update agents
agents:deleteDelete agents
workflows:readRead workflows
workflows:writeCreate/update workflows
workflows:deleteDelete workflows
tools:readRead tools
tools:writeCreate/update tools
calls:readRead call history
calls:writeInitiate calls
provider-keys:readRead provider keys
provider-keys:writeManage provider keys

Wildcard Scopes

Use * suffix for all permissions on a resource:

  • agents:* = agents:read + agents:write + agents:delete
  • * = All permissions on all resources

Scope Validation

Requests are validated against the token's scopes:

# This requires agents:read scope
GET /api/v1/agents

# This requires agents:write scope
POST /api/v1/agents

# This requires agents:delete scope
DELETE /api/v1/agents/meal-agent

Security Best Practices

JWT Tokens

  1. Store securely: Use httpOnly cookies or secure storage
  2. Refresh proactively: Refresh before expiry to avoid interruptions
  3. Handle expiry: Implement automatic refresh in your client
  4. Logout properly: Clear tokens and call logout endpoint

API Keys

  1. Never commit keys: Use environment variables
  2. Rotate regularly: Create new keys periodically
  3. Minimal scopes: Only request necessary permissions
  4. Monitor usage: Check for unusual activity
  5. Use test keys: Use as_test_* keys for development

General

  1. Use HTTPS: Always use TLS in production
  2. Validate inputs: Never trust client data
  3. Log access: Monitor authentication attempts
  4. Rate limit: Protect against brute force

Error Handling

Authentication Errors

HTTP StatusCodeDescription
401authentication_errorInvalid or missing credentials
401token_expiredJWT token has expired
401invalid_tokenToken is malformed or invalid
401key_revokedAPI key has been revoked

Example Error Response:

{
  "error": {
    "code": "token_expired",
    "message": "Token has expired"
  }
}

Authorization Errors

HTTP StatusCodeDescription
403authorization_errorInsufficient permissions
403scope_requiredMissing required scope

Example Error Response:

{
  "error": {
    "code": "scope_required",
    "message": "This action requires the 'agents:write' scope"
  }
}

Code Examples

Python

import httpx

# With API Key
client = httpx.Client(
    base_url="https://api.agentstudio.dev/api/v1",
    headers={"X-API-Key": "as_live_xxx"}
)

agents = client.get("/agents").json()

JavaScript/TypeScript

// With JWT
const response = await fetch('https://api.agentstudio.dev/api/v1/agents', {
  headers: {
    'Authorization': `Bearer ${accessToken}`
  }
});

const agents = await response.json();

cURL

# With API Key
curl -H "X-API-Key: as_live_xxx" \
  https://api.agentstudio.dev/api/v1/agents

# With JWT
curl -H "Authorization: Bearer eyJ..." \
  https://api.agentstudio.dev/api/v1/agents

On this page