Vercel AI SDK
The Vercel AI SDK emphasizes developer experience and streaming. Use Glitch as the underlying client to secure inputs, retrieved context, and streaming outputs.
Configuration
Section titled “Configuration”import { openai } from '@ai-sdk/openai';import { generateText } from 'ai';
// Configure OpenAI provider with Glitchconst glitchModel = openai('gpt-4', { baseURL: 'https://api.golabrat.ai/v1', apiKey: process.env.GLITCH_API_KEY!, // Your Glitch API key});Basic Example
Section titled “Basic Example”import { openai } from '@ai-sdk/openai';import { generateText, streamText } from 'ai';
// Configure with Glitchconst model = openai('gpt-4', { baseURL: 'https://api.golabrat.ai/v1', apiKey: process.env.GLITCH_API_KEY!,});
// Generate text - automatically securedconst result = await generateText({ model, prompt: 'What is the capital of France?',});
console.log(result.text);
// Streaming is also securedconst stream = await streamText({ model, prompt: 'Write a poem about AI',});
for await (const chunk of stream.textStream) { process.stdout.write(chunk);}Error Handling
Section titled “Error Handling”Handle security blocks gracefully:
import { generateText } from 'ai';
try { const result = await generateText({ model, prompt: userInput, }); return result.text;} catch (error: any) { if (error?.status === 403 || error?.statusCode === 403) { // Security block - handle gracefully return "I can't process that request."; } throw error;}Streaming Support
Section titled “Streaming Support”Glitch fully supports streaming responses with the Vercel AI SDK:
import { streamText } from 'ai';
const stream = await streamText({ model, prompt: 'Write a long story',});
for await (const chunk of stream.textStream) { process.stdout.write(chunk);}Next Steps
Section titled “Next Steps”- Frameworks Overview — Other framework integrations
- Quick Start — Get running in 5 minutes
- API Reference — Full endpoint documentation