GitHub 37
Skip to content
ViteHub is still experimental. Expect bugs and breaking changes.

AI Gateways

One object knows where AI requests go and how to sign them. Agents, Choices, and your routes share it.

server/api/answer.get.ts
import { generateText } from 'ai'
import { defineEventHandler } from 'h3'
import { openrouter } from 'vite-hub/gateways'
import { languageModel } from 'vite-hub/gateways/ai-sdk'

// Reads OPENROUTER_API_KEY when it sends the request
const model = languageModel(openrouter(), 'google/gemini-3.8-flash')

export default defineEventHandler(async () => {
  const { text } = await generateText({ model, prompt: 'What is a Server Primitive?' })
  return { text }
})
server/api/answer.get.ts

Use it with the AI SDK

languageModel() returns an AI SDK model that sends its requests through the gateway.

Route Codex and Claude Code

Set driver.gateway, and the Agent Driver sends its model requests through your proxy.

Typed data from one call

ask(prompt, { model, schema }) returns data that your schema checked, without an Agent. Without schema, it returns text.

Ask typed questions

ask() sends questions to TypeSafe Jev and TypeScript infers each answer type.

A preset for each provider

Presets cover Vercel, Cloudflare, OpenRouter, LiteLLM, CLIProxyAPI, Ollama, OpenAI, Anthropic, Google, Moonshot AI, Z.ai, DeepSeek, MiniMax, Alibaba Cloud, and TypeSafe. The type tells what each one serves.

Keys stay on the server

Presets read their API key on each request, so rotated keys apply at once.

No framework code

The package has no Agent, Vite, or Nitro code. It also runs in a plain Node script or a Worker.