Skip to content

Authentication

The Exnest AI SDKs use API keys for authentication. You can obtain an API key from the Exnest Dashboard.

It is recommended to use environment variables to store your API key securely.

The SDK automatically looks for the EXNEST_API_KEY environment variable.

Terminal window
export EXNEST_API_KEY="your_api_key_here"
import { ExnestAI } from '@exnest-dev/ai';
// No need to pass apiKey if env var is set
const client = new ExnestAI();

You can also pass the API key directly to the constructor.

const client = new ExnestAI({
apiKey: 'your_api_key_here',
});

Exnest supports both Exnest API keys (prefixed with ex-sk) and official provider API keys through the Universal Connector feature. This allows you to:

  • Use your existing API keys from providers like OpenAI, Anthropic, etc.
  • Still benefit from Exnest’s unified API interface
  • Optionally use Exnest’s billing and management features when using Exnest API keys
const exnest = new ExnestAI({
apiKey: 'ex-sk-your-exnest-api-key'
});
const response = await exnest.chat('gpt-4.1-mini', [
{ role: 'user', content: 'Hello!' }
]);

Using Official Provider API Keys (without billing)

Section titled “Using Official Provider API Keys (without billing)”
const exnest = new ExnestAI({
apiKey: 'sk-your-openai-api-key'
});
const response = await exnest.chat('gpt-4.1-mini', [
{ role: 'user', content: 'Hello!' }
]);