Authentication

The AI SDK CLI requires authentication to access AI models through the AI Gateway. This guide will walk you through setting up your API key and configuring environment variables.

Prerequisites

To use the AI SDK CLI, you'll need:

  • Node.js 18+ and pnpm installed on your local development machine.
  • An AI Gateway API key.

If you haven't obtained your AI Gateway API key, you can do so by visiting the Vercel Dashboard and navigating to the AI tab.

Configure API Key

Export your AI Gateway API Key as an environment variable. This key is used to authenticate your application with the AI Gateway service.

For temporary use in your current session:

export AI_GATEWAY_API_KEY="your-key-here"

Replace your-key-here with your actual AI Gateway API key.

The AI SDK CLI will default to using the AI_GATEWAY_API_KEY environment variable.

Environment Variables

You can configure additional environment variables to customize the CLI behavior:

AI_DEFAULT_MODEL

Set a default model to avoid specifying it with each command:

export AI_DEFAULT_MODEL="anthropic/claude-3-5-sonnet"

AI_SYSTEM

Set a default system message:

export AI_SYSTEM="You are a helpful assistant."

AI_VERBOSE

Enable detailed output by default:

export AI_VERBOSE="true"

Shell Configuration

For persistent configuration across terminal sessions, you can add environment variables to your shell profile:

Bash
Zsh
echo 'export AI_GATEWAY_API_KEY="your-key"' >> ~/.bashrc && source ~/.bashrc

Verify Setup

Test your authentication setup by running a simple command:

npx ai "Hello, world!"

If authentication is successful, you should see a response from the AI model. If you encounter authentication errors, double-check that your API key is correctly set and valid.