Skip to main content
The Narrative SDK uses API keys for authentication. This guide covers how to configure authentication securely and manage credentials across different environments.

Prerequisites

Authentication methods

Store your API key in an environment variable to keep it out of source control:
Set the environment variable before running your application:

Using a .env file

For local development, use a .env file with a package like dotenv:
Create a .env file in your project root:
Load the environment variables in your code:
Never commit .env files to source control. Add .env to your .gitignore file.

Direct configuration

For testing or when credentials are managed externally:
Avoid hardcoding API keys in source code. Use environment variables or a secrets manager in production.

Environment selection

The SDK supports multiple environments:

Verifying authentication

Test your credentials by making a simple API call:

Updating credentials at runtime

You can change the API key after initialization:

Security best practices

Troubleshooting

API Keys

Create and manage API keys

Configuration Reference

Complete configuration options

Error Handling

Handle authentication errors gracefully

Permissions Reference

All available permission resources and access levels