Skip to content

Commit 20398f2

Browse files
authored
feat: ai sdk cli documentation + adjusted default model (#7368)
## background The AI CLI proper documentation for authentication setup, added to help users get started ## summary - add AI CLI authentication documentation - update AI CLI index - change AI_MODEL to AI_DEFAULT_MODEL environment variable ## tasks - [x] create authentication documentation page - [x] rename AI_MODEL to AI_DEFAULT_MODEL in CLI code - [x] remove Vercel OIDC token references
1 parent c93a8bc commit 20398f2

File tree

6 files changed

+131
-16
lines changed

6 files changed

+131
-16
lines changed

‎.changeset/late-socks-flash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'ai': patch
3+
---
4+
5+
feat: ai sdk cli documentation + adjusted default model
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
title: Authentication
3+
description: Learn how to set up authentication for the AI SDK CLI.
4+
---
5+
6+
# Authentication
7+
8+
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.
9+
10+
## Prerequisites
11+
12+
To use the AI SDK CLI, you'll need:
13+
14+
- Node.js 18+ and pnpm installed on your local development machine.
15+
- An AI Gateway API key.
16+
17+
If you haven't obtained your AI Gateway API key, you can do so by visiting the [Vercel Dashboard](https://vercel.com/dashboard) and navigating to the **AI** tab.
18+
19+
## Configure API Key
20+
21+
Export your AI Gateway API Key as an environment variable. This key is used to authenticate your application with the AI Gateway service.
22+
23+
For temporary use in your current session:
24+
25+
<Snippet text='export AI_GATEWAY_API_KEY="your-key-here"' />
26+
27+
Replace `your-key-here` with your actual AI Gateway API key.
28+
29+
<Note className="mb-4">
30+
The AI SDK CLI will default to using the `AI_GATEWAY_API_KEY` environment
31+
variable.
32+
</Note>
33+
34+
## Environment Variables
35+
36+
You can configure additional environment variables to customize the CLI behavior:
37+
38+
### AI_DEFAULT_MODEL
39+
40+
Set a default model to avoid specifying it with each command:
41+
42+
<Snippet text='export AI_DEFAULT_MODEL="anthropic/claude-3-5-sonnet"' />
43+
44+
### AI_SYSTEM
45+
46+
Set a default system message:
47+
48+
<Snippet text='export AI_SYSTEM="You are a helpful assistant."' />
49+
50+
### AI_VERBOSE
51+
52+
Enable detailed output by default:
53+
54+
<Snippet text='export AI_VERBOSE="true"' />
55+
56+
## Shell Configuration
57+
58+
For persistent configuration across terminal sessions, you can add environment variables to your shell profile:
59+
60+
<div className="my-4">
61+
<Tabs items={['Bash', 'Zsh']}>
62+
<Tab>
63+
<Snippet
64+
text={
65+
'echo \'export AI_GATEWAY_API_KEY="your-key"\' >> ~/.bashrc && source ~/.bashrc'
66+
}
67+
dark
68+
/>
69+
</Tab>
70+
<Tab>
71+
<Snippet
72+
text={
73+
'echo \'export AI_GATEWAY_API_KEY="your-key"\' >> ~/.zshrc && source ~/.zshrc'
74+
}
75+
dark
76+
/>
77+
</Tab>
78+
</Tabs>
79+
</div>
80+
81+
## Verify Setup
82+
83+
Test your authentication setup by running a simple command:
84+
85+
<Snippet text='npx ai "Hello, world!"' />
86+
87+
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.

‎content/docs/10-cli/index.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: AI SDK CLI
3+
description: Learn about the AI SDK CLI.
4+
---
5+
6+
# AI SDK CLI
7+
8+
The AI SDK CLI is a command-line tool for interacting with AI models directly from your terminal. Generate text, attach files, and stream responses using a simple command-line interface.
9+
10+
<Snippet text="npx ai@beta 'Hello, world!'" />
11+
12+
## Getting Started
13+
14+
To start using the AI SDK CLI, you'll need to set up authentication and learn the basic usage patterns:
15+
16+
<IndexCards
17+
cards={[
18+
{
19+
title: 'Authentication',
20+
description: 'Learn how to set up authentication for the AI SDK CLI.',
21+
href: '/docs/ai-sdk-cli/authentication',
22+
},
23+
]}
24+
/>

‎packages/ai/src/bin/ai.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('AI CLI', () => {
109109
});
110110

111111
it('should handle environment variables with defaults', async () => {
112-
process.env.AI_MODEL = 'groq/llama-3.1-8b-instant';
112+
process.env.AI_DEFAULT_MODEL = 'groq/llama-3.1-8b-instant';
113113
process.env.AI_SYSTEM = 'Be concise';
114114
process.env.AI_VERBOSE = 'true';
115115
process.argv = ['node', 'ai', 'test prompt'];
@@ -232,10 +232,9 @@ describe('AI CLI', () => {
232232
233233
Authentication (required):
234234
export AI_GATEWAY_API_KEY="your-key" # Get from Vercel Dashboard (AI tab)
235-
export VERCEL_OIDC_TOKEN="your-token" # For Vercel projects (or run: vercel env pull)
236-
235+
237236
Environment Variables:
238-
AI_MODEL: Default model to use
237+
AI_DEFAULT_MODEL: Default model to use
239238
AI_SYSTEM: Default system message
240239
AI_VERBOSE: Set to 'true' for detailed output
241240
@@ -252,7 +251,9 @@ describe('AI CLI', () => {
252251
cat README.md | npx ai "Summarize this"
253252
curl -s https://api.github.com/repos/vercel/ai | npx ai "What is this repository about?"
254253
255-
The gateway supports OpenAI, Anthropic, Google, Groq, and more providers."
254+
The gateway supports OpenAI, Anthropic, Google, Groq, and more providers.
255+
256+
For detailed setup instructions, visit: https://ai-sdk.dev/docs/cli/authentication"
256257
`);
257258

258259
consoleSpy.mockRestore();

‎packages/ai/src/bin/ai.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export function parseArgs(): CLIOptions {
9595
const args = process.argv.slice(2);
9696

9797
const options: CLIOptions = {
98-
model: process.env.AI_MODEL || 'openai/gpt-4',
98+
model: process.env.AI_DEFAULT_MODEL || 'openai/gpt-4',
9999
files: [],
100100
help: false,
101101
version: false,
@@ -182,10 +182,9 @@ Options:
182182
183183
Authentication (required):
184184
export AI_GATEWAY_API_KEY="your-key" # Get from Vercel Dashboard (AI tab)
185-
export VERCEL_OIDC_TOKEN="your-token" # For Vercel projects (or run: vercel env pull)
186-
185+
187186
Environment Variables:
188-
AI_MODEL: Default model to use
187+
AI_DEFAULT_MODEL: Default model to use
189188
AI_SYSTEM: Default system message
190189
AI_VERBOSE: Set to 'true' for detailed output
191190
@@ -202,7 +201,9 @@ Unix-style piping:
202201
cat README.md | npx ai "Summarize this"
203202
curl -s https://api.github.com/repos/vercel/ai | npx ai "What is this repository about?"
204203
205-
The gateway supports OpenAI, Anthropic, Google, Groq, and more providers.`);
204+
The gateway supports OpenAI, Anthropic, Google, Groq, and more providers.
205+
206+
For detailed setup instructions, visit: https://ai-sdk.dev/docs/cli/authentication`);
206207
}
207208

208209
export function showVersion() {
@@ -293,21 +294,18 @@ export async function main(): Promise<void> {
293294
console.error('');
294295
}
295296

296-
const hasApiKey =
297-
process.env.AI_GATEWAY_API_KEY || process.env.VERCEL_OIDC_TOKEN;
297+
const hasApiKey = process.env.AI_GATEWAY_API_KEY;
298298
if (!hasApiKey) {
299299
console.error(`Error: Authentication required.
300300
301301
Set up authentication with one of these options:
302302
303303
# Option 1: Export in current session
304304
export AI_GATEWAY_API_KEY="your-key-here"
305-
export VERCEL_OIDC_TOKEN="your-oidc-token"
306-
export AI_MODEL="anthropic/claude-3-5-sonnet"
305+
export AI_DEFAULT_MODEL="anthropic/claude-3-5-sonnet"
307306
308307
# Option 2: Add to shell profile (~/.bashrc, ~/.zshrc)
309308
echo 'export AI_GATEWAY_API_KEY="your-key"' >> ~/.bashrc
310-
# Or run: vercel env pull
311309
312310
Get your API key from the Vercel Dashboard (AI tab > API keys).
313311
Use --help for more details and examples.`);

‎turbo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"GOOGLE_VERTEX_LOCATION",
3131
"GOOGLE_VERTEX_PROJECT",
3232
"GROQ_API_KEY",
33-
"AI_MODEL",
33+
"AI_DEFAULT_MODEL",
3434
"AI_SYSTEM",
3535
"AI_VERBOSE",
3636
"LUMA_API_KEY",

0 commit comments

Comments
 (0)