Agent may make mistakes. Verify all outputs.
Agent may make mistakes. Verify all outputs.
These examples require Node.js 22.18 or later.
Set up AI Gateway for text generation in my existing Node.js project. Reuse `AI_GATEWAY_API_KEY` if it is already configured without exposing its value. If it is missing, run the Vercel CLI through `npx vercel@latest`; no global install is required. Check authentication with `npx vercel@latest whoami`. If login is required, pause and ask me to run `npx vercel@latest login`. Determine the target team from the linked project or current CLI scope; if it is ambiguous, ask me for the team slug. Then run `npx vercel@latest --scope <team-slug> ai-gateway api-keys create --name <descriptive-name>`. Capture the command's stdout directly into the project's ignored secret storage as `AI_GATEWAY_API_KEY`; never print or paste the plaintext key into chat. Use Node.js 22.18 or later and install only `ai@latest`. Create `index.mts` that uses `generateText` with `openai/gpt-5.6-sol`, prints the generated text, runs with `AI_GATEWAY_API_KEY` loaded, and reports the output.
Create an API Key, then export it in the terminal running the example.
export AI_GATEWAY_API_KEY="your_api_key_here"Alternatively, use OIDC tokens for automatic authentication in Vercel deployments.
Install the AI SDK in your Node.js project.
pnpm add ai@latestSave this script as index.mts, then run it with Node.js.
import { generateText } from 'ai';
async function main() { const { text } = await generateText({ model: 'openai/gpt-5.6-sol', prompt: 'Invent a new holiday and describe its traditions.', });
console.log(text);}
main().catch(console.error);node index.mtsNext steps: Learn about provider routing, OpenAI compatibility, or Anthropic compatibility.