# Vertex AI Studio proxy

> Google AI Studio (Gemini API) and OpenAI/OpenRouter-compatible REST API backed by Gemini on Vertex AI (Google Cloud "Gemini Enterprise Agent Platform"). Tools written for AI Studio or OpenRouter work unchanged: change the base URL and the API key.

- Gemini API (AI Studio) base URL: `https://flash.rushwick.com` - REST paths `/v1beta/...` (also `/v1/...`, `/v1alpha/...`)
- OpenAI base URL: `https://flash.rushwick.com/v1` - aliases `https://flash.rushwick.com/api/v1` (OpenRouter), `https://flash.rushwick.com/openai/v1`, `https://flash.rushwick.com/v1beta/openai` (Google's OpenAI-compatible path)
- Live API (WebSocket, voice): `wss://flash.rushwick.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent` - see "Live API" below
- Default model: `gemini-3.8-flash` (used when a request names no model)
- OpenAPI 3.1: https://flash.rushwick.com/openapi.json (YAML: https://flash.rushwick.com/openapi.yaml) - interactive docs: https://flash.rushwick.com/docs - full guide: https://flash.rushwick.com/llms-full.txt

## Authentication

Use a key of this proxy (issued in its dashboard), not a Google API key. Send it in any of:
- `x-goog-api-key: <key>` (google-genai SDKs) or `?key=<key>` (AI Studio REST samples)
- `Authorization: Bearer <key>` (OpenAI / OpenRouter SDKs)
- `x-api-key: <key>`

The proxy calls Vertex AI with its own Google Cloud service account; your key never leaves the proxy.

## Models

From the proxy's catalog; prices are list prices in USD per 1M tokens (Vertex AI Standard PayGo). `GET /v1beta/models` and `GET /v1/models` return the same catalog.

| id | context | max output | input -> output | thinking levels | list $ per 1M in / out | notes | aliases |
|---|---|---|---|---|---|---|---|
| `gemini-4-neon` | 1,048,576 | 1,048,576 | text, image, audio, video, file -> text | LOW/MEDIUM/HIGH (default MEDIUM) | $3.00 / $15.00 | temperature/top_p/top_k ignored (removed); penalties removed; no prefill; implicit caching only (no cachedContents); agentic video (mediaProcessing AGENTIC) | - |
| `gemini-4-carbon` | 1,048,576 | 1,048,576 | text, image, audio, video, file -> text | LOW/MEDIUM/HIGH (default MEDIUM) | $4.00 / $20.00 | temperature/top_p/top_k ignored (removed); penalties removed; no prefill; implicit caching only (no cachedContents); agentic video (mediaProcessing AGENTIC); intro price $2.00/$10.00 until 2026-11-30 | - |
| `gemini-4-argon` | 1,048,576 | 1,048,576 | text, image, audio, video, file -> text | LOW/MEDIUM/HIGH (default MEDIUM) | $4.00 / $20.00 | temperature/top_p/top_k ignored (removed); penalties removed; no prefill; implicit caching only (no cachedContents); agentic video (mediaProcessing AGENTIC); intro price $2.00/$10.00 until 2026-11-30 | - |
| `gemini-3.8-flash` (default) | 1,048,576 | 65,536 | text, image, audio, video, file -> text | LOW/MEDIUM/HIGH (default MEDIUM) | $1.50 / $7.50 | temperature/top_p/top_k ignored (removed); penalties removed; candidateCount > 1 -> 400; no prefill; agentic video (mediaProcessing AGENTIC); intro price $0.75/$3.75 until 2026-12-31 | `gemini-flash-latest` |
| `gemini-3.7-flash` | 1,048,576 | 65,536 | text, image, audio, video, file -> text | LOW/MEDIUM/HIGH (default MEDIUM) | $1.50 / $7.50 | temperature/top_p/top_k ignored (removed); penalties removed; candidateCount > 1 -> 400; no prefill; agentic video (mediaProcessing AGENTIC); intro price $0.75/$3.75 until 2026-12-31 | - |
| `gemini-3.6-flash` | 1,048,576 | 65,536 | text, image, audio, video, file -> text | MINIMAL/LOW/MEDIUM/HIGH (default MEDIUM) | $1.50 / $7.50 | temperature/top_p/top_k ignored (removed); penalties removed; candidateCount > 1 -> 400; no prefill; agentic video (mediaProcessing AGENTIC); intro price $0.75/$3.75 until 2026-12-31 | - |
| `gemini-3.5-flash` | 1,048,576 | 65,536 | text, image, audio, video, file -> text | MINIMAL/LOW/MEDIUM/HIGH (default MEDIUM) | $1.50 / $9.00 | - | - |
| `gemini-3.5-flash-lite` | 1,048,576 | 65,536 | text, image, audio, video, file -> text | MINIMAL/LOW/MEDIUM/HIGH (default MINIMAL) | $0.30 / $2.50 | agentic video (mediaProcessing AGENTIC) | `gemini-flash-lite-latest` |
| `gemini-3.1-flash-lite` | 1,048,576 | 65,536 | text, image, audio, video, file -> text | MINIMAL/LOW/MEDIUM/HIGH (default MINIMAL) | $0.25 / $1.50 | audio input $0.50 | - |
| `gemini-3.1-pro-preview` | 1,048,576 | 65,536 | text, image, audio, video, file -> text | LOW/MEDIUM/HIGH (default HIGH) | $2.00 / $12.00 | preview; global endpoint only; >200K prompt $4.00/$18.00 | `gemini-3-pro-preview`, `gemini-pro-latest` |
| `gemini-3-flash-preview` | 1,048,576 | 65,536 | text, image, audio, video, file -> text | MINIMAL/LOW/MEDIUM/HIGH (default HIGH) | $0.50 / $3.00 | preview; global endpoint only; audio input $1.00 | - |
| `gemini-2.5-pro` | 1,048,576 | 65,536 | text, image, audio, video, file -> text | budget 128..32768 | $1.25 / $10.00 | retires 2026-10-20; >200K prompt $2.50/$15.00 | - |
| `gemini-2.5-flash` | 1,048,576 | 65,536 | text, image, audio, video, file -> text | budget 0..24576 | $0.30 / $2.50 | retires 2026-10-20; audio input $1.00 | - |
| `gemini-2.5-flash-lite` | 1,048,576 | 65,536 | text, image, audio, video, file -> text | budget 0..24576 | $0.10 / $0.40 | retires 2026-10-20; audio input $0.30 | - |
| `gemini-3.1-flash-image` | 131,072 | 32,768 | text, image, video -> text, image | MINIMAL/HIGH (default MINIMAL) | $0.50 / $3.00 | image generation; image output $60.00 | `gemini-3.1-flash-image-preview`, `nano-banana` |
| `gemini-3.1-flash-lite-image` | 65,536 | 4,096 | text, image, video -> text, image | MINIMAL/HIGH (default MINIMAL) | $0.25 / $1.50 | image generation; global endpoint only; image output $30.00 | - |
| `gemini-3-pro-image` | 65,536 | 32,768 | text, image -> text, image | HIGH (default HIGH) | $2.00 / $12.00 | image generation; global endpoint only; image output $120.00 | `gemini-3-pro-image-preview`, `nano-banana-pro` |
| `gemini-2.5-flash-image` | 32,768 | 32,768 | text, image -> text, image | - | $0.30 / $2.50 | image generation; retires 2027-03-15; image output $30.00 | `gemini-2.5-flash-image-preview` |
| `gemini-3.1-flash-tts-preview` | 8,192 | 16,384 | text -> audio | - | $1.00 / $20.00 | text-to-speech; preview; global endpoint only | `gemini-3.8-flash-lite-tts`, `gemini-3.8-flash-tts` |
| `gemini-2.5-flash-tts` | 8,192 | 16,384 | text -> audio | - | $0.50 / $10.00 | text-to-speech | `gemini-2.5-flash-preview-tts` |
| `gemini-2.5-pro-tts` | 8,192 | 16,384 | text -> audio | - | $1.00 / $20.00 | text-to-speech | `gemini-2.5-pro-preview-tts` |
| `gemini-3.5-transcribe-preview` | 1,048,576 | 65,536 | audio, text -> text | - | $2.00 / $12.00 | speech-to-text; preview; global endpoint only | `gemini-3.5-transcribe` |
| `gemini-3.8-live` | 131,072 | 65,536 | text, image, audio, video -> text, audio | - | $0.75 / $4.50 | Live API (WebSocket bidiGenerateContent); audio input $3.00; audio output $12.00 | - |
| `gemini-3.8-live-extended-thinking` | 131,072 | 65,536 | text, image, audio, video -> text, audio | LOW/MEDIUM/HIGH | $0.75 / $4.50 | Live API (WebSocket bidiGenerateContent); audio input $3.00; audio output $12.00 | - |
| `gemini-embedding-2` | 8,192 | 1 | text, image, audio, video, file -> embedding | - | $0.20 in | embeddings; audio input $6.50; 3072 dims | `gemini-embedding-2-preview` |
| `gemini-embedding-001` | 2,048 | 1 | text -> embedding | - | $0.15 in | embeddings; 3072 dims | - |

## How to call it

### Gemini API with curl
```bash
curl "https://flash.rushwick.com/v1beta/models/gemini-3.8-flash:generateContent" \
  -H "x-goog-api-key: $PROXY_KEY" -H "Content-Type: application/json" \
  -d '{"contents":[{"parts":[{"text":"Explain how AI works in a few words"}]}],"generationConfig":{"thinkingConfig":{"thinkingLevel":"LOW"}}}'
```

Streaming (Server-Sent Events):
```bash
curl -N "https://flash.rushwick.com/v1beta/models/gemini-3.8-flash:streamGenerateContent?alt=sse" \
  -H "x-goog-api-key: $PROXY_KEY" -H "Content-Type: application/json" \
  -d '{"contents":[{"parts":[{"text":"Write a haiku about the sea"}]}]}'
```

### Python google-genai
```python
import os
from google import genai
from google.genai import types

# or: export GOOGLE_GEMINI_BASE_URL=https://flash.rushwick.com GEMINI_API_KEY=<proxy key> and keep genai.Client() unchanged
client = genai.Client(api_key=os.environ["PROXY_KEY"], http_options={"base_url": "https://flash.rushwick.com"})

resp = client.models.generate_content(
    model="gemini-3.8-flash",
    contents="Explain how AI works in a few words",
    config=types.GenerateContentConfig(thinking_config=types.ThinkingConfig(thinking_level="low")),
)
print(resp.text)

for chunk in client.models.generate_content_stream(model="gemini-3.8-flash", contents="Write a haiku about the sea"):
    print(chunk.text or "", end="")
```

Keep the SDK in Gemini API mode (no `vertexai=True` / `enterprise=True`): the proxy speaks the AI Studio protocol.

### JavaScript @google/genai
```javascript
import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({ apiKey: process.env.PROXY_KEY, httpOptions: { baseUrl: "https://flash.rushwick.com" } });
const r = await ai.models.generateContent({ model: "gemini-3.8-flash", contents: "Explain how AI works in a few words" });
console.log(r.text);
```

### OpenAI / OpenRouter
```bash
curl https://flash.rushwick.com/v1/chat/completions \
  -H "Authorization: Bearer $PROXY_KEY" -H "Content-Type: application/json" \
  -d '{"model":"gemini-3.8-flash","reasoning_effort":"low","messages":[{"role":"user","content":"Hello!"}]}'
```

```python
import os
from openai import OpenAI

# OpenAI SDK: base https://flash.rushwick.com/v1 ; OpenRouter apps: base https://flash.rushwick.com/api/v1 and model "google/gemini-3.8-flash"
client = OpenAI(base_url="https://flash.rushwick.com/v1", api_key=os.environ["PROXY_KEY"])

resp = client.chat.completions.create(
    model="gemini-3.8-flash",
    messages=[{"role": "user", "content": "Hello!"}],
    reasoning_effort="low",
)
print(resp.choices[0].message.content)

stream = client.chat.completions.create(
    model="gemini-3.8-flash", stream=True, messages=[{"role": "user", "content": "Write a haiku about the sea"}]
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")
```

Environment variables for unchanged programs: `GOOGLE_GEMINI_BASE_URL=https://flash.rushwick.com` + `GEMINI_API_KEY=<proxy key>`;
`OPENAI_BASE_URL=https://flash.rushwick.com/v1` + `OPENAI_API_KEY=<proxy key>`; OpenRouter apps: base URL `https://flash.rushwick.com/api/v1`.

## Live API (WebSocket)

Same protocol as AI Studio's Live API (BidiGenerateContent): connect to `wss://flash.rushwick.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent`
(also `v1alpha`, `v1`) with the proxy key in `x-goog-api-key`, `?key=` or `Authorization: Bearer`; send
`{"setup": {"model": "models/gemini-3.8-live", ...}}` first, then `clientContent` / `realtimeInput` /
`toolResponse`. google-genai works unchanged: `client.aio.live.connect(model="gemini-3.8-live", config=...)` with
`http_options={"base_url": "https://flash.rushwick.com"}` (the SDK always uses wss://).

- Models: `gemini-3.8-live`, `gemini-3.8-live-extended-thinking` (Vertex location us-central1,
  LIVE_LOCATION). Audio in: 16-bit PCM 16 kHz; audio out: 16-bit PCM 24 kHz.
- Server messages are sent as binary frames with JSON (like AI Studio); `usageMetadata` uses AI Studio names
  (`responseTokenCount`). `realtimeInput.audioStreamEnd` is sent to Vertex as 1 s of silence.
- Errors close the socket like Google: 1007 bad key or argument, 1008 unknown/non-Live model, 1009 message over
  16777216 bytes, 1011 spend limit or Vertex error, 1001 idle 600 s,
  1012 proxy restart (reconnect with `sessionResumption`).
- A Vertex connection lasts about 10 minutes (`goAway` comes 60 s before the end): enable `sessionResumption` and
  reconnect with the last `newHandle`; `contextWindowCompression` lifts the 15 min audio session limit.
- The spend limit is checked when a session opens; usage is recorded every 60 s
  and at close. Price per 1M tokens: input text $0.75, audio $3.00, image/video $1.00; output text $4.50,
  audio $12.00 (+10% outside `global`).
- On Cloud Run WebSockets need a service without HTTP/2 end-to-end (`USE_HTTP2=false` in deploy/deploy.sh).

## Service tiers: standard, flex, priority

Pick the tier per request. The proxy never changes it on its own; without the field a request is `standard`.

| tier | how to request | price | latency | use it for |
|---|---|---|---|---|
| `standard` | omit the field (or `"standard"`) | 1x | normal (a short answer takes a few seconds) | interactive chat, anything a human waits for |
| `flex` | Gemini API: `"serviceTier": "flex"` (google-genai: `service_tier="flex"`); OpenAI/OpenRouter: `"service_tier": "flex"` | 0.5x | queues when Vertex is busy: seconds to minutes, up to 30 min (a trivial request took ~12 s instead of ~2 s) | background agents, bulk processing, summarization, evals, video/document analysis nobody watches live |
| `priority` | `"priority"` | 1.8x | fastest under load; if Vertex has no priority capacity the request runs (and is billed) as standard | latency-critical calls |

Prices per 1M tokens, USD, Vertex AI list prices (input / output; output includes thinking tokens):

| model | standard in / out | flex (x0.5) | priority (x1.8) | intro price |
|---|---|---|---|---|
| `gemini-4-neon` | $3.00 / $15.00 | $1.50 / $7.50 | $5.40 / $27.00 | - |
| `gemini-4-carbon` | $4.00 / $20.00 | $2.00 / $10.00 | $7.20 / $36.00 | $2.00 / $10.00 -> flex $1.00 / $5.00 (until 2026-11-30) |
| `gemini-4-argon` | $4.00 / $20.00 | $2.00 / $10.00 | $7.20 / $36.00 | $2.00 / $10.00 -> flex $1.00 / $5.00 (until 2026-11-30) |
| `gemini-3.8-flash` | $1.50 / $7.50 | $0.75 / $3.75 | $2.70 / $13.50 | $0.75 / $3.75 -> flex $0.375 / $1.875 (until 2026-12-31) |
| `gemini-3.7-flash` | $1.50 / $7.50 | $0.75 / $3.75 | $2.70 / $13.50 | $0.75 / $3.75 -> flex $0.375 / $1.875 (until 2026-12-31) |
| `gemini-3.6-flash` | $1.50 / $7.50 | $0.75 / $3.75 | $2.70 / $13.50 | $0.75 / $3.75 -> flex $0.375 / $1.875 (until 2026-12-31) |
| `gemini-3.5-flash` | $1.50 / $9.00 | $0.75 / $4.50 | $2.70 / $16.20 | - |
| `gemini-3.5-flash-lite` | $0.30 / $2.50 | $0.15 / $1.25 | $0.54 / $4.50 | - |
| `gemini-3.1-flash-lite` | $0.25 / $1.50 | $0.125 / $0.75 | $0.45 / $2.70 | - |
| `gemini-3.1-pro-preview` | $2.00 / $12.00 | $1.00 / $6.00 | $3.60 / $21.60 | - |
| `gemini-3-flash-preview` | $0.50 / $3.00 | $0.25 / $1.50 | $0.90 / $5.40 | - |

The intro price on Vertex is paid back as a 50% credit after the fact (it does apply to Google Cloud Free Trial
credits: the trial balance goes down at the intro price). The proxy's own estimates use
intro prices (`PRICING_MODE=intro`). Flex halves
whatever price applies.

- Streaming works in every tier (`streamGenerateContent`, `"stream": true`).
- Check the tier you actually got: Gemini responses have `usageMetadata.serviceTier` (`standard` / `flex` /
  `priority`), OpenAI responses have top-level `service_tier`. The proxy's cost estimate (`usage.cost`, dashboard,
  spend limits) follows this value: flex is counted at 0.5x only when Vertex really served it as flex.
- Flex limits: preview (no latency guarantee), global endpoint only (this proxy uses it), at most 20 MB of inline
  data per request (the proxy moves larger inline media to Cloud Storage automatically), 3000 requests per minute
  per model per project. Client timeouts must allow up to ~31 min (openai SDK: `timeout=1900`; google-genai:
  `http_options={"timeout": 1900000}`); the proxy itself waits up to 31 min for flex.

```bash
curl "https://flash.rushwick.com/v1beta/models/gemini-3.8-flash:generateContent" -H "x-goog-api-key: $PROXY_KEY"   -H "Content-Type: application/json"   -d '{"contents":[{"parts":[{"text":"Summarize this report"}]}],"serviceTier":"flex"}'
curl "https://flash.rushwick.com/api/v1/chat/completions" -H "Authorization: Bearer $PROXY_KEY" -H "Content-Type: application/json"   -d '{"model":"google/gemini-3.8-flash","service_tier":"flex","messages":[{"role":"user","content":"Summarize this report"}]}'
```

```python
from openai import OpenAI
client = OpenAI(base_url="https://flash.rushwick.com/api/v1", api_key=PROXY_KEY, timeout=1900)
r = client.chat.completions.create(model="google/gemini-3.8-flash", service_tier="flex",
                                   messages=[{"role": "user", "content": "Summarize this report"}])
print(r.service_tier, r.usage)  # "flex"
```

## Big media: Files API

Inline data works for small media (Vertex limit: 7 MB per inline image; inline payloads above
6 MiB, and the largest ones when all inline data of a request exceeds
13 MiB, are moved to Cloud Storage by the proxy). Request bodies above 110 MiB (MAX_REQUEST_BYTES) get 413, bodies over 32 MiB are processed at most 2 at a time per instance (others wait up to 120 s, then 503); Files API uploads are not limited. For long videos, long audio and big PDFs
upload once with the Files API and reference the file:

1. `POST https://flash.rushwick.com/upload/v1beta/files` with `X-Goog-Upload-Protocol: resumable`, `X-Goog-Upload-Command: start`,
   `X-Goog-Upload-Header-Content-Length`, `X-Goog-Upload-Header-Content-Type` -> `x-goog-upload-url` header.
2. `POST <x-goog-upload-url>` 8 MiB chunks with `X-Goog-Upload-Offset` and `X-Goog-Upload-Command: upload`
   (last: `upload, finalize`) -> `{"file": {"uri": "https://flash.rushwick.com/v1beta/files/<id>", "state": "ACTIVE", ...}}`.
3. Use `{"fileData": {"fileUri": "<file.uri>", "mimeType": "video/mp4"}}` in generateContent (or a
   `video_url` / `file` part on the OpenAI surface). The proxy rewrites it to a gs:// object for Vertex AI.

Files: 2 GB each, expire after 48 h, `state` is ACTIVE immediately (no polling needed).
`POST https://flash.rushwick.com/v1beta/files:register` with `{"uris": ["gs://bucket/object"]}` registers existing Cloud Storage objects.
gs:// URIs (in `fileData`, OpenAI parts and files:register) must point to the proxy bucket (FILES_BUCKET) or a bucket
listed in ALLOWED_GCS_BUCKETS, otherwise 400. Text documents (markdown, csv, html, json, code) are sent to Vertex AI
as `text/plain` (the File keeps its original `mimeType`). `:download` returns the bytes as an attachment.

```python
import os
from google import genai

client = genai.Client(api_key=os.environ["PROXY_KEY"], http_options={"base_url": "https://flash.rushwick.com"})

video = client.files.upload(file="lecture.mp4")  # resumable upload in 8 MiB chunks, state is ACTIVE at once
resp = client.models.generate_content(
    model="gemini-3.8-flash",
    contents=[video, "Summarize this lecture and list key moments as MM:SS."],
)
print(resp.text)
client.files.delete(name=video.name)  # optional: files expire on their own
```

## Parameter translation

- Gemini 3.6+ Flash (gemini-3.6-flash, gemini-3.7-flash, gemini-3.8-flash), gemini-4-carbon and gemini-4-argon: `temperature`,
  `topP`/`top_p`, `topK`/`top_k`, `presencePenalty`, `frequencyPenalty` and logprobs are removed (the models ignore or
  reject them); a trailing text-only model/assistant turn (prefill) is removed. On the 3.6+ Flash models
  `candidateCount` > 1 -> 400 on the Gemini surface and OpenAI `n` > 1 (max 8) is served as n parallel requests (each
  billed; with `seed`, request i uses seed + i; not with `stream: true`); gemini-4-carbon and gemini-4-argon support `candidateCount`.
- Thinking levels: gemini-3.8-flash, gemini-4-carbon and gemini-4-argon accept LOW, MEDIUM (default), HIGH - MINIMAL is mapped to LOW;
  `none` / `off` mean the lowest supported level, any other unknown level is 400 INVALID_ARGUMENT.
  `thinkingBudget` on Gemini 3.x -> level (0 -> lowest, <=1024 LOW, <=8192 MEDIUM, else HIGH);
  levels on Gemini 2.5 -> budget (LOW 1024, MEDIUM 8192, HIGH max). Level and budget are never sent together.
- OpenAI `reasoning_effort` / OpenRouter `reasoning.effort`: none/minimal -> lowest supported level (LOW on
  gemini-3.8-flash, gemini-4-carbon and gemini-4-argon), low -> LOW, medium -> MEDIUM, high/xhigh/max -> HIGH. `reasoning.max_tokens` -> level as above.
  `reasoning.exclude: true` or `include_reasoning: false` hides thought summaries.
- Thought summaries: Gemini parts with `thought: true` (set `thinkingConfig.includeThoughts: true`); OpenAI surface:
  `message.reasoning`, `reasoning_content`, `reasoning_details[]` (type `reasoning.text`, format `google-gemini-v1`).
- Thought signatures (required for multi-step tool use on Gemini 3): Gemini surface - send back the model turn with
  `thoughtSignature` unchanged. OpenAI surface - each tool call has `extra_content.google.thought_signature` and a
  matching `reasoning_details` item `{"type": "reasoning.encrypted", "id": <tool_call_id>, "data": <signature>}`;
  send the assistant message back as received. The proxy also caches signatures by tool_call id and, as a last
  resort, uses `skip_thought_signature_validator`.
- Tool results: every functionResponse must carry the `id` and `name` of its functionCall; OpenAI `tool` messages are
  grouped into one Gemini turn automatically.
- Structured output: `responseMimeType: application/json` + `responseJsonSchema` (or `responseSchema`); OpenAI
  `response_format: {"type": "json_schema", ...}` maps to the same.
- Web search: Gemini `tools: [{"googleSearch": {}}]`; OpenAI/OpenRouter: model suffix `:online`,
  `plugins: [{"id": "web"}]`, `web_search_options` or a `web_search` tool -> citations in `message.annotations`.
- Service tiers: `serviceTier` / `service_tier` = `standard` (default), `flex` (half price, may queue) or `priority`
  (1.8x) - see "Service tiers" above.
- Video: on gemini-4-neon, gemini-4-carbon, gemini-4-argon, gemini-3.8-flash, gemini-3.7-flash, gemini-3.6-flash, gemini-3.5-flash-lite video parts without `mediaProcessing` (OpenAI: `video_url.processing`) get `AGENTIC` (DEFAULT_VIDEO_PROCESSING). AGENTIC lets the model pick which segments to watch (fewer tokens on long videos, better for questions about specific moments); send `"mediaProcessing": "STATIC"` (OpenAI: `"processing": "static"`) for uniform 1 fps sampling, e.g. a full transcript or a summary of every scene. In multi-turn chats send the model turn back unchanged: its signed parts carry the navigation steps.
- Long outputs (gemini-4-carbon, gemini-4-argon): one request returns at most 32,768 output tokens (65,536 when streaming), then the
  candidate ends with `finishReason: "CONTINUATION"` and a `continuationToken`. Gemini surface: resend the same request
  with `"continuationToken": <token>` (google-genai >= 2.30.1 does it automatically) and append the new parts.
  OpenAI/OpenRouter surface: the proxy continues by itself (up to 40 times) and returns one
  answer; `usage` sums every request of the chain. Each continuation is billed as a request whose prompt includes the
  text produced so far; `maxOutputTokens` / `max_tokens` counts across the chain.
- Caching on gemini-4-carbon and gemini-4-argon: implicit only (prefixes of 6,144+ tokens, automatic); `cachedContents` -> 400.
- Not available on Vertex AI: `tools[].fileSearch`, `tools[].mcpServers` (400). AI Studio-only fields
  (`store`, `enableEnhancedCivicAnswers`, ...) are removed silently.
- Image output: image models (`gemini-3.1-flash-image`) with `responseModalities: ["TEXT","IMAGE"]` / OpenAI
  `modalities: ["image","text"]`; images come back as inlineData / `message.images[]` data URLs.
- Speech: TTS models (`gemini-3.1-flash-tts-preview`) with `responseModalities: ["AUDIO"]` + speechConfig, or
  `POST /v1/audio/speech` (24 kHz 16-bit mono; `wav` default on /v1, `pcm` default on /api/v1; mp3/opus -> 400;
  OpenAI voices such as alloy/nova are mapped to Gemini voices, `tts-1` -> gemini-2.5-flash-tts). Chat with
  `modalities: ["audio"]`: `audio.format` `wav` (default) or `pcm16`/`pcm`; mp3/opus/flac/aac -> 400.
- Every Gemini-surface response carries an `x-proxy-notes` header when the proxy changed something in the request.

## Limits

Vertex AI per prompt (gemini-3.8-flash; similar for other Gemini 3 Flash models):
- 1 audio file per prompt (about 8.4 hours or 1M tokens)
- 10 videos per prompt (about 45 min with audio, about 1 h without)
- 3,000 images per prompt; 7 MB per inline image, 30 MB per image from Cloud Storage
- PDF: 50 MB per file, 3,000 pages; text/plain: 7 MB
- Public https URLs: audio, video and documents at most 15 MB each; at most 1 video, 1 audio and 10 images per request
- YouTube: 1 URL per request (public or owned by the project's account)
- gs:// URIs: objects Vertex AI can read (same project or public); the proxy accepts only FILES_BUCKET and buckets listed in ALLOWED_GCS_BUCKETS

Proxy and Cloud Run:
- Request timeout up to 60 minutes; OpenAI-surface streams get `: keep-alive` SSE comments while the model thinks.
  The proxy waits 1260 s for Vertex (UPSTREAM_TIMEOUT), or the request's `X-Server-Timeout`
  + 60 s (flex sends 1800), at most 3600 s.
- Request bodies above 110 MiB (MAX_REQUEST_BYTES) get 413, bodies over 32 MiB are processed at most 2 at a time per instance (others wait up to 120 s, then 503); Files API uploads are not limited.
- Files API: 2 GB per file, files expire after 48 h.
- Vertex 429/5xx are retried 3 times with exponential backoff; persistent quota errors
  return 429 RESOURCE_EXHAUSTED. The global endpoint is used to reduce 429s.
- Spend limit: none configured (SPEND_LIMIT_USD).
  The estimate counts Priority traffic at 1.8x, us/eu endpoints at +10% (Gemini 3+), models without a catalog price
  (EXTRA_MODELS, unknown `gemini-*`, Interactions agents) at the most expensive catalog price of their kind, and
  context cache storage for the whole TTL.
- Context caches: at least 4,096 tokens (Gemini 3), minimum TTL 60 s; a longer TTL than 86400 s (MAX_CACHE_TTL_SECONDS) is clamped (see `x-proxy-notes`).

## Errors

- AI Studio paths: `{"error": {"code": 400, "message": "...", "status": "INVALID_ARGUMENT"}}`
  (401 UNAUTHENTICATED, 404 NOT_FOUND, 429 RESOURCE_EXHAUSTED, 503 UNAVAILABLE, 504 DEADLINE_EXCEEDED).
  Mid-stream errors: `data: {"error": {...}}`.
- OpenAI paths (`/v1/chat/completions`, `/v1/embeddings`, `/api/v1/*`, `/openai/v1/*`, `/v1beta/openai/*`):
  `{"error": {"message": "...", "type": "invalid_request_error", "param": null, "code": 400}}`.
  Mid-stream errors: a chunk with `error` and `finish_reason: "error"`.
- `/v1/models` answers in the Gemini format when the key comes as `x-goog-api-key`/`?key=`, otherwise OpenAI format.

## Links

- [OpenAPI 3.1 (JSON)](https://flash.rushwick.com/openapi.json): every route, request/response schemas, examples
- [Interactive docs](https://flash.rushwick.com/docs)
- [Full guide](https://flash.rushwick.com/llms-full.txt)
- [Models (Gemini format)](https://flash.rushwick.com/v1beta/models) - [Models (OpenAI/OpenRouter format)](https://flash.rushwick.com/v1/models) (need a key)
