NarrativeApi class accepts a configuration object that controls authentication, environment targeting, and request behavior.
Constructor options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | undefined | API key for authentication. Passed as a Bearer token. |
environment | 'prod' | 'dev' | string | 'prod' | Target environment or custom base URL |
headers | Record<string, string> | {} | Additional HTTP headers to include in requests |
verbose | boolean | false | Enable verbose logging (automatically enabled in dev) |
Environment URLs
The SDK supports two built-in environments, or you can specify a custom URL:| Environment | Base URL |
|---|---|
prod | https://api.narrative.io/ |
dev | https://api-dev.narrative.io/ |
| Custom | Any valid URL you provide |
Configuration examples
Production (default)
Development environment
Custom base URL
For self-hosted or custom deployments:Enable verbose logging
Useful for debugging API requests:- Request URLs and methods
- Request payloads
- Response data
- Configuration details
Verbose mode is automatically enabled when using the
dev environment.Custom headers
Add custom headers to all requests:Runtime configuration
You can update the API key after initialization:Environment variables
While the SDK doesn’t automatically read environment variables, the recommended pattern is:| Variable | Description |
|---|---|
NARRATIVE_API_KEY | Your API key for authentication |
NARRATIVE_ENVIRONMENT | Target environment (prod, dev, or custom URL) |
TypeScript types
The SDK exports configuration types for TypeScript users:Related content
API Keys
Create and manage API keys
Authentication Guide
Authentication best practices
SDK Overview
TypeScript SDK overview
API Modules
Available API methods

