Overview
All S2 API requests require authentication using Bearer tokens in theAuthorization header. Access tokens are managed through the S2 account API and can be scoped to specific resources and operations.
Access Tokens
Access tokens are string credentials that authenticate your API requests. They are:- Hierarchical - Root tokens can create scoped child tokens
- Scoped - Restrict access to specific basins, streams, or operations
- Expirable - Optional expiration time for security
- Revocable - Can be revoked at any time
Authentication Header
Include your access token in theAuthorization header:
Example Request
Getting Your First Token
For S2.dev (managed service):- Sign up at s2.dev
- Your initial root token is provided in the dashboard
- Export it as an environment variable:
Creating Scoped Tokens
Create child tokens with restricted permissions using the access tokens API.Issue a Token
The full token value is only returned when created. Store it securely as it cannot be retrieved later.
Token Scope
Control what a token can access using scope configuration.Resource Scoping
Restrict access to specific resources:Exact Match
Allow access to a single resource:Prefix Match
Allow access to resources starting with a prefix:All Resources
Use empty prefix to allow all:No Access
Use empty exact match to deny all:Operation Scoping
Control what operations a token can perform.Operation Groups
Grant read and/or write permissions at different levels:- Account: List basins, access tokens, account metrics
- Basin: Create/delete basins, configure basin settings, basin metrics
- Stream: Create/delete streams, append/read records, stream metrics
Specific Operations
Grant access to individual operations:- Account:
list-basins,create-basin,delete-basin,reconfigure-basin,get-basin-config,issue-access-token,revoke-access-token,list-access-tokens,account-metrics - Basin:
basin-metrics - Stream:
list-streams,create-stream,delete-stream,get-stream-config,reconfigure-stream,check-tail,append,read,trim,fence,stream-metrics
Operation permissions are the union of
op_groups and ops. A token is granted access if either allows the operation.Auto-Prefixing Streams
Automatic stream name prefixing provides namespace isolation:- Token can only access streams starting with
service-a/ - Stream names in requests are automatically prefixed with
service-a/ - Stream names in responses have the prefix stripped
Token Expiration
Set an expiration time when creating tokens:expires_at is not specified, the token inherits the expiration of the parent token used to create it.
Managing Tokens
List Tokens
Retrieve metadata about existing tokens (not the secret values):Revoke a Token
Revoke a token to immediately invalidate it:Revoking a token also revokes all child tokens created from it.
Security Best Practices
1. Use Scoped Tokens
Create tokens with minimal required permissions:2. Rotate Tokens Regularly
Periodically create new tokens and revoke old ones:3. Use Environment Variables
Never hardcode tokens in source code:4. Limit Token Scope by Service
Create separate tokens for each service or environment:Error Responses
401 Unauthorized
Missing or invalid token:403 Forbidden
Token lacks required permissions:SDK Support
S2 SDKs handle authentication automatically:Rust SDK
CLI
Next Steps
API Overview
Learn about API structure and endpoints
Quickstart
Get started with S2 in minutes