PromptRails

API Keys and Scopes

Create and manage API keys with fine-grained scopes, IP restrictions, CORS origin allowlists, and key expiration.

API Keys and Scopes

API keys authenticate programmatic access to the PromptRails API. Each key can be scoped to specific permissions, restricted by IP address and CORS origin, and configured with an expiration date.

Creating API Keys

Create an API key from the PromptRails dashboard:

  1. Open Settings > API Keys.
  2. Select Create API Key.
  3. Enter a name and choose the minimum required scopes.
  4. Optionally add IP restrictions, allowed origins, and an expiration date.
  5. Create the key and store the raw value securely.

The raw API key value is returned only at creation time. It is stored as a hash and cannot be retrieved later.

Scopes

Scopes control what operations an API key can perform. PromptRails defines 24 granular scopes:

Agent Scopes

ScopeDescription
agents:readList and view agents and their versions
agents:writeCreate, update, and delete agents and versions
agents:executeExecute agents

Prompt Scopes

ScopeDescription
prompts:readList and view prompts and their versions
prompts:writeCreate, update, and delete prompts and versions
prompts:executeExecute prompts directly

Data Source Scopes

ScopeDescription
data_sources:readList and view data sources
data_sources:writeCreate, update, and delete data sources
data_sources:executeExecute data source queries

Execution and Trace Scopes

ScopeDescription
executions:readList and view execution records
traces:readList and view trace spans

Credential Scopes

ScopeDescription
credentials:readList and view credentials (masked values only)
credentials:writeCreate, update, and delete credentials

Session and Chat Scopes

ScopeDescription
sessions:readList and view chat sessions
chat:writeSend messages to chat sessions

Webhook Trigger Scopes

ScopeDescription
webhook_triggers:readList and view webhook triggers
webhook_triggers:writeCreate, update, and delete webhook triggers

Score Scopes

ScopeDescription
scores:readList and view scores and score configs
scores:writeCreate and update scores and score configs

Approval Scopes

ScopeDescription
approvals:readList and view approval requests
approvals:writeApprove or reject approval requests

Asset Scopes

ScopeDescription
assets:readList and view generated media assets
assets:writeDelete assets and manage asset storage

Wildcard Scope

ScopeDescription
*Grants all permissions (use with caution)

IP Restrictions

Restrict API key usage to specific IP addresses or CIDR ranges when creating or editing the key in the dashboard. You can mix individual IPs and CIDR ranges, including IPv6 entries.

Requests from IPs not in the allowlist receive a 403 Forbidden response.

CORS Origin Restrictions

Restrict which web origins can use the API key by adding an allowlist in the dashboard. This is most relevant for browser-based applications.

Key Expiration

Set an expiration date on API keys when creating or editing the key in the dashboard.

Expired keys are automatically rejected. Use last_used_at to identify stale keys.

Key Format

API keys follow this format:

  • Full key: Returned only at creation time (e.g., pr_live_abc123...xyz789)
  • Key prefix: Stored and displayed for identification (e.g., pr_live_ab)
  • Key hash: SHA-256 hash stored in the database for authentication

Authentication

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

curl -H "X-API-Key: pr_live_abc123...xyz789" \
     https://api.promptrails.ai/api/v1/agents

The same key can also be used with the PromptRails SDKs and CLI for authenticating requests.

Managing Keys

List, review, rotate, and delete API keys from Settings > API Keys in the dashboard.

Key Rotation Best Practices

  • Rotate keys regularly -- Create a new key, update your applications, then delete the old key
  • Use expiration dates -- Set keys to expire and create replacement keys before expiration
  • Minimize scopes -- Grant only the permissions each integration needs
  • Use separate keys per environment -- Different keys for development, staging, and production
  • Monitor usage -- Check last_used_at to identify unused keys
  • Never share keys -- Each integration should have its own key
  • Store securely -- Keep keys in environment variables or secret managers, never in source code

Key Response Fields

FieldTypeDescription
idKSUIDUnique key identifier
workspace_idKSUIDWorkspace scope
namestringDisplay name
key_prefixstringFirst characters for identification
scopesarrayGranted permission scopes
allowed_ipsarrayIP allowlist
allowed_originsarrayCORS origin allowlist
last_used_attimestampLast usage time
expires_attimestampExpiration time
created_attimestampCreation time