# Use your own Gemini API key or Google Cloud credits through a gateway

> Use your Google Cloud credits or Gemini API key through an OpenAI-compatible gateway without changing your codebase or risking surprise fallbacks.

**You can use your Google Cloud credits for Gemini models through thelastapi gateway by adding your Gemini API key from Google AI Studio to your account or project settings.** Once configured, any call to Gemini models—including `vibiz/balanced`, `vibiz/image`, and explicit `google/…` model IDs—routes directly through your key, charging your Google account instead of your thelastapi balance. The gateway returns a cost of zero on thelastapi while letting your application keep a single OpenAI-compatible client for all model providers.

This setup lets you spend down promotional credits or enterprise commitments without splitting your code across multiple vendor SDKs.

## Why route Gemini calls through a gateway when you have Google credits?

Startups and development teams frequently receive Google Cloud credits, but modern applications rarely rely on a single model lab. You might prefer Claude Sonnet for complex coding tasks, GPT-6 Luna for structured tool calling, and Gemini for cost-effective multimodal tasks or long context windows.

Calling each lab directly creates operational friction:
- **Code fragmentation**: You end up maintaining separate SDKs, custom error handling, and different request-response schemas for each provider.
- **Scattered telemetry**: Calculating spend per feature or per user requires pulling logs and CSV exports from multiple billing dashboards.
- **Rigid architecture**: Switching a feature from Gemini to another model requires rewriting the client logic rather than updating a model parameter.

Routing your requests through an [OpenAI-compatible API for Claude and Gemini](https://thelastapi.dev/blog/openai-compatible-api-claude-gemini) solves this. By registering your Google key with thelastapi, you preserve a single API surface. Google handles the billing for Gemini calls against your existing credits, while the gateway manages logging, per-user budget enforcement, and connectivity to other labs.

## How to add your Gemini API key

You can register a Gemini API key at the account level or scope it to a specific project. An account-level key applies across all your projects, while a project key (`/v1/projects/:id/ai-keys/google`) overrides the account key for that specific project.

### Step 1: Set the key via CLI or console

In the console, navigate to **API keys ▸ Your AI keys**. 

From the terminal using the CLI, provide your key directly or through an environment variable:

```bash
GEMINI_API_KEY=AIzaSyD... vibiz ai keys set google
```

You can also run `vibiz ai keys set google` without inline arguments to paste the key at a hidden prompt. 

If you prefer calling the HTTP API directly with a full-access key:

```bash
curl -X PUT https://thelastapi.dev/v1/ai-keys/google \
  -H "Authorization: Bearer $VIBIZ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"type": "gemini_api_key", "api_key": "AIzaSyD..."}'
```

Setting or rotating provider keys requires a full-access key (`access: owner`). Agents or automated tokens with Limited access (`access: agent`) cannot view or modify these credentials, as detailed in the documentation for [Keys and environments](https://thelastapi.dev/docs/keys).

### Step 2: Verification and storage

When you submit a key, thelastapi immediately tests it with a free call to Google before storing it. If Google rejects the credential, the save operation is refused and returns the specific provider error.

Once accepted, the key is encrypted at rest and never displayed in full again. The console and CLI only expose the last 4 characters, the timestamp when it was last used, and the status of the most recent check.

### Step 3: Test the configuration

Verify the connection at any time using the CLI:

```bash
vibiz ai keys test google
```

To inspect which models are active on your own key versus the gateway's default billing, run:

```bash
vibiz ai keys
```

## Which models run on your key and which run on thelastapi?

Registering a Google key does not move all traffic to Google. Only Google-native models are routed through your credential. Requests for Anthropic, OpenAI, DeepSeek, or other lab models continue to route through the gateway and are billed against your prepaid balance on thelastapi.

| Model identifier | Underlying lab model | Charged to | Default gateway price |
| --- | --- | --- | --- |
| `vibiz/balanced` | Gemini 3.8 Flash (Google) | Your Google key ($0 here) | $0.825 / $4.125 per M tokens |
| `vibiz/image` | Nano Banana 2 (Google) | Your Google key ($0 here) | ~$0.067 per image |
| `vibiz/image-pro` | Nano Banana 2.1 (Google) | Your Google key ($0 here) | ~$0.034 per image |
| `google/gemini-4-argon` | Gemini 4 Argon (Google) | Your Google key ($0 here) | Lab list price |
| `google/gemini-omni-1.1-flash` | Gemini Omni 1.1 Flash | Your Google key ($0 here) | Lab list price |
| `vibiz/fast` | GPT-6 Luna (OpenAI) | thelastapi credits | $0.10 / $0.50 per M tokens |
| `vibiz/smart` | Claude Sonnet 5.5 (Anthropic) | thelastapi credits | $2.00 / $10.00 per M tokens |
| `vibiz/lite` | DeepSeek V4.1 Flash | thelastapi credits | $0.14 / $0.42 per M tokens |

Every response processed through your key includes metadata indicating zero platform cost:

```json
{
  "paid_by": "your_key",
  "would_cost_micro_usd": 825
}
```

The `would_cost_micro_usd` field shows what the call would have cost on standard platform billing, helping you track how much value you have extracted from your Google Cloud credits.

### A note on embeddings and audio

To protect vector search integrity, embeddings do not automatically switch to your key. Vector representations can vary across model configurations, and silently altering embedding vectors would corrupt existing similarity indexes. To route embeddings through your Google credential, opt in explicitly:

```bash
curl -X PATCH https://thelastapi.dev/v1/ai-keys/google \
  -H "Authorization: Bearer $VIBIZ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"use_for": ["llm", "embeddings"]}'
```

Additionally, speech generation (`vibiz/voice` or `google/gemini-3.8-flash-tts`) running on your Google key returns audio formatted as `audio/wav`, even if `mp3` was requested. Audio transcription through your Google key supports file uploads up to 14 MB.

## What happens when your Google key fails or hits a quota?

A common failure mode in secondary gateways is silent fallback: when a custom key runs out of quota, the platform silently redirects the call to its own paid account and charges you. 

As explained in [why your AI gateway should never swap models silently](https://thelastapi.dev/blog/no-silent-model-fallback), thelastapi enforces strict failure boundaries. If a request targets a model served by your Google key, it runs **only** on your Google key.

If Google rejects your request, encounters an outage, or hits an API quota limit, the call immediately fails with an OpenAI-compatible error response:
- `provider_failed` with `details.reason: "customer_key_rejected"`
- `provider_unavailable` when Google returns transient server errors

The gateway will never retry a rejected call on our own account behind your back. You maintain complete control over where spend lands. Similarly, if you remove your key while an asynchronous video or image generation job is queued, the job will fail rather than execute on our billing.

## How to call Gemini with the OpenAI SDK

Once your key is linked, your code remains identical whether you use Gemini, Claude, or GPT models. You can continue using standard OpenAI client libraries pointing to the gateway endpoint. Read more on how this is structured in [one API key for GPT, Claude and Gemini](https://thelastapi.dev/blog/one-api-key-gpt-claude-gemini).

```ts
import OpenAI from 'openai';

// VIBIZ_AI_BASE_URL: https://thelastapi.dev/v1/ai
// VIBIZ_AI_API_KEY: vz_ai_... or vz_sk_...
const client = new OpenAI({
  baseURL: process.env.VIBIZ_AI_BASE_URL,
  apiKey: process.env.VIBIZ_AI_API_KEY,
});

// 1. Routed through your Google key (billed to Google credits, $0 here)
const geminiResponse = await client.chat.completions.create({
  model: 'vibiz/balanced',
  messages: [{ role: 'user', content: 'Extract key points from this briefing.' }],
});

// 2. Explicit Google model ID on your key
const customGemini = await client.chat.completions.create({
  model: 'google/gemini-4-argon',
  messages: [{ role: 'user', content: 'Analyze this code structure.' }],
});

// 3. Routed through the gateway balance (Anthropic)
const claudeResponse = await client.chat.completions.create({
  model: 'vibiz/smart',
  messages: [{ role: 'user', content: 'Draft a contract amendment.' }],
});
```

If you are using the official app client library, the [@vibiz/app](https://thelastapi.dev/docs/app-sdk) package simplifies initialization:

```ts
import { vibiz } from '@vibiz/app';
import OpenAI from 'openai';

const openai = new OpenAI(vibiz.ai);
```

## Viewing usage, costs, and verification

Even when calls cost zero dollars on thelastapi, the gateway records token volume, latency, and request metadata. You can track this traffic alongside your other services.

Check your usage breakdown from the command line:

```bash
vibiz usage --by model --period 7d
```

To review remaining balances, payment settings, or daily ceilings across your account, use:

```bash
vibiz billing
```

Calls run on your own key continue to respect the account's rate limits (300 requests and 400k tokens per minute on an account key; 120 requests and 200k tokens per minute on a project key) and project-level guardrails, protecting your applications from runaway client-side loops. Full details on spend caps are documented in [Usage and limits](https://thelastapi.dev/docs/usage).

To remove your key and revert all Gemini routing back to thelastapi standard billing, execute:

```bash
vibiz ai keys remove google
```

Explore the full catalogue of supported models, parameter options, and multi-modal endpoints in the [AI docs](https://thelastapi.dev/docs/ai).

## Frequently asked questions

### Can I use both Google Cloud credits and normal platform credits at the same time?

Yes. When a Google key is set, Gemini models and Google image models run on your key at zero platform charge, while models from OpenAI, Anthropic, or DeepSeek draw against your prepaid thelastapi balance.

### Will my Gemini calls fail over to thelastapi if my Google credits expire?

No. thelastapi never silently falls back to its own account when your custom key fails or exhausts its budget; you will receive a `customer_key_rejected` or `provider_failed` error instead.

### Do embeddings automatically use my Gemini API key?

No, embeddings remain on the platform's default routing by default so existing vector stores do not get corrupted. You can enable embeddings on your key using `PATCH /v1/ai-keys/google` with `use_for: ["llm", "embeddings"]`.

### What audio format is returned when using text-to-speech with a Google key?

Speech requests routed through your own Google key return `audio/wav` format, even if your API call requested `mp3`.

---

Published 2026-11-15 · https://thelastapi.dev/blog/use-your-own-gemini-key
