Documentation

Vercel AI

How to use GATE/0 with Vercel AI

GATE/0 works out of the box with the Vercel AI SDK (e.g., ai from @vercel/ai) by simply updating the API endpoint and adding custom headers. This lets you track and allocate LLM costs without changing how your app functions.

Here’s how to use GATE/0 with the Vercel AI SDK:

import { generateText } from 'ai';
import { createOpenAI } from '@ai-sdk/openai';

const openai = createOpenAI({
    baseURL: "https://gateway.gate0.io/v1", // GATE0 cloud proxy URL
    apiKey: process.env.GATE0_API_KEY, // API key provided by GATE0
  });

const result = await generateText({
  model: openai('openai/gpt-4o'), // Model name with provider prefix
  prompt: 'Hello, how are you?',
  headers: { // Custom labels
    'x-gate0-label-project': 'alpha', 
    'x-gate0-label-client': 'frontend', 
    'x-gate0-label-env': 'prod'
  }
});

console.log(result)