Superagent LogoSuperagent

Vercel AI Gateway Integration

Route Vercel AI Gateway requests through Superagent for enhanced security

Superagent can be configured to work with Vercel AI Gateway by configuring the gateway provider with your Superagent proxy URL. This adds AI firewall protection to your multi-provider AI applications.

AI SDK with Gateway Provider

Using Gateway Provider
import { gateway } from '@ai-sdk/gateway';
import { generateText } from 'ai';

const gatewayProvider = gateway({
  apiKey: 'your-vercel-ai-gateway-api-key',
  baseURL: 'YOUR_SUPERAGENT_PROXY_URL', // Replace with your Superagent proxy
});

// Use with any Vercel AI Gateway model
const { text } = await generateText({
  model: gatewayProvider('xai/grok-3'),
  prompt: 'Explain quantum computing',
});

Direct Model Specification

Direct Model Usage
import { generateText } from 'ai';

// Configure gateway globally with Superagent proxy
const { text } = await generateText({
  model: 'xai/grok-3', // Direct model specification
  prompt: 'Hello world',
});

Python (OpenAI SDK Compatible)

Python with OpenAI SDK
from openai import OpenAI

client = OpenAI(
    api_key="your-vercel-ai-gateway-api-key",
    base_url="YOUR_SUPERAGENT_PROXY_URL"  # Replace with your Superagent proxy
)

# Use any model from Vercel AI Gateway
response = client.chat.completions.create(
    model="xai/grok-3",
    messages=[{"role": "user", "content": "Hello world"}]
)

TypeScript/JavaScript (OpenAI SDK)

TypeScript with OpenAI SDK
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'your-vercel-ai-gateway-api-key',
  baseURL: 'YOUR_SUPERAGENT_PROXY_URL', // Replace with your Superagent proxy
});

// Use any model from Vercel AI Gateway
const response = await client.chat.completions.create({
  model: 'openai/gpt-4o',
  messages: [{ role: 'user', content: 'Hello world' }],
});

Embeddings

Embeddings with Gateway
import { embed } from 'ai';

const { embedding } = await embed({
  model: 'openai/text-embedding-3-small',
  value: 'Your text to embed',
});

Available Models

Popular models accessible through Vercel AI Gateway:

  • xAI: xai/grok-3, xai/grok-2
  • OpenAI: openai/gpt-4o, openai/gpt-4o-mini, openai/gpt-3.5-turbo
  • Anthropic: anthropic/claude-3-5-sonnet-20241022
  • Google: google/gemini-2.0-flash-exp, google/gemini-1.5-pro
  • Meta: meta/llama-3.1-405b-instruct, meta/llama-3.1-70b-instruct
  • Mistral: mistral/mistral-large-2411, mistral/pixtral-12b-2409

Dynamic Model Discovery

List Available Models
import { gateway } from '@ai-sdk/gateway';

const gatewayProvider = gateway({
  apiKey: 'your-vercel-ai-gateway-api-key',
  baseURL: 'YOUR_SUPERAGENT_PROXY_URL',
});

// Get all available models
const models = await gatewayProvider.getAvailableModels();

// Filter by type
const languageModels = models.filter(model => model.type === 'language');
const embeddingModels = models.filter(model => model.type === 'embedding');

Configuration Benefits

  • Multi-Provider Protection: Secure access to 100+ AI models through one proxy
  • Unified Security: Consistent threat detection across all providers
  • No Provider Management: Keep Vercel's unified API while adding security
  • Model Discovery: Dynamic model listing with added protection
  • Easy Switching: Switch between models while maintaining security

Migration Notes

  • Gateway Provider: Use @ai-sdk/gateway with custom baseURL
  • Model Format: Use provider/model-name format (e.g., xai/grok-3)
  • All Features Supported: Streaming, embeddings, function calling work normally
  • Added Security: All requests now protected by Superagent's AI firewall

Configure the gateway provider with your Superagent proxy URL to add comprehensive AI security to your multi-provider setup!