Google Gemini

The @ai-proxy/google package is a drop-in replacement for @ai-sdk/google. Swap the import, point it at your TypoMonster proxy, and everything else stays the same.

Installation

bash
npm install @ai-proxy/google ai

Setup

typescript
import { createProxyGoogle } from "@ai-proxy/google";
 
const google = createProxyGoogle({
  apiKey: "tmk_your_api_key_here",
});

You can also configure via environment variables instead of passing them directly:

VariableDescription
NEXT_PUBLIC_AI_PROXY_KEYYour TypoMonster API key (tmk_...)
NEXT_PUBLIC_AI_PROXY_URLProxy URL (defaults to https://chat-api.typo.monster)
typescript
// When env vars are set, no config needed
const google = createProxyGoogle();

Available Models

ModelDescription
gemini-2.5-proMost capable model, best for complex tasks
gemini-2.5-flashFast and efficient, great balance of speed and quality
gemini-2.0-flashPrevious generation flash model
gemini-2.0-flash-liteLightweight model for simple tasks

Text Generation

typescript
import { createProxyGoogle } from "@ai-proxy/google";
import { generateText } from "ai";
 
const google = createProxyGoogle({
  apiKey: "tmk_your_api_key_here",
});
 
const { text } = await generateText({
  model: google("gemini-2.5-flash"),
  prompt: "What is the capital of France?",
});
 
console.log(text);

Streaming

typescript
import { createProxyGoogle } from "@ai-proxy/google";
import { streamText } from "ai";
 
const google = createProxyGoogle({
  apiKey: "tmk_your_api_key_here",
});
 
const result = streamText({
  model: google("gemini-2.5-flash"),
  prompt: "Write a short story about a robot.",
});
 
for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}

Multi-turn Chat

typescript
import { createProxyGoogle } from "@ai-proxy/google";
import { generateText } from "ai";
 
const google = createProxyGoogle({
  apiKey: "tmk_your_api_key_here",
});
 
const { text } = await generateText({
  model: google("gemini-2.5-flash"),
  system: "You are a helpful cooking assistant.",
  messages: [
    { role: "user", content: "What can I make with eggs and cheese?" },
    { role: "assistant", content: "You could make an omelette, quiche, or cheese souffl\u00e9!" },
    { role: "user", content: "How do I make a souffl\u00e9?" },
  ],
});
 
console.log(text);

Structured Output

Generate type-safe structured data using Zod schemas:

typescript
import { createProxyGoogle } from "@ai-proxy/google";
import { generateObject } from "ai";
import { z } from "zod";
 
const google = createProxyGoogle({
  apiKey: "tmk_your_api_key_here",
});
 
const { object } = await generateObject({
  model: google("gemini-2.5-flash"),
  schema: z.object({
    name: z.string(),
    ingredients: z.array(z.string()),
    steps: z.array(z.string()),
  }),
  prompt: "Give me a recipe for chocolate chip cookies.",
});
 
console.log(object.name);
console.log(object.ingredients);

Reasoning (Thinking)

Gemini 2.5 models support extended thinking. Enable it via provider options:

typescript
import { createProxyGoogle } from "@ai-proxy/google";
import { generateText } from "ai";
 
const google = createProxyGoogle({
  apiKey: "tmk_your_api_key_here",
});
 
const { text, reasoning } = await generateText({
  model: google("gemini-2.5-flash"),
  prompt: "How many r's are in the word strawberry?",
  providerOptions: {
    google: {
      thinkingConfig: { thinkingBudget: 8000 },
    },
  },
});
 
console.log("Answer:", text);
console.log("Reasoning:", reasoning);

To disable thinking (on by default for 2.5 models):

typescript
providerOptions: {
  google: {
    thinkingConfig: { thinkingBudget: 0 },
  },
}

Migrating from @ai-sdk/google

The migration is a two-line change:

diff
- import { createGoogleGenerativeAI } from "@ai-sdk/google";
+ import { createProxyGoogle } from "@ai-proxy/google";
 
- const google = createGoogleGenerativeAI({
-   apiKey: "YOUR_GOOGLE_API_KEY",
- });
+ const google = createProxyGoogle({
+   apiKey: "tmk_your_api_key_here",
+ });
 
// Everything below stays exactly the same
const { text } = await generateText({
  model: google("gemini-2.5-flash"),
  prompt: "Hello!",
});

Next Steps