← Back to Blog

Google AI Studio Base URL Override: Use Gemini with Any OpenAI-Compatible Tool (2026)

2026-08-14·3 min read·CodeRouter Team
google ai studio base url overridegemini openai compatible endpointgemini api base urluse gemini with openai sdkgoogle ai studio api key openaigemini custom base url

TL;DR — Google ships an official OpenAI-compatible endpoint for Gemini: point your tool's base URL at https://generativelanguage.googleapis.com/v1beta/openai/, use your Google AI Studio API key as the OpenAI key, and use full Gemini model names (e.g. gemini-3-flash). Most "base URL override" failures come from three mistakes: missing the /openai/ suffix, using an OpenAI model name instead of a Gemini one, or a tool that hardcodes its model list. Fixes for each below — and if you're juggling multiple providers' base URLs, that's the exact problem a router solves with one endpoint.

The official override, step by step

Google AI Studio keys work with any OpenAI-compatible client via Google's compatibility layer:

OpenAI SDK (Python):

from openai import OpenAI

client = OpenAI(
    base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
    api_key=os.environ["GOOGLE_AI_STUDIO_KEY"],  # AI Studio key, not a GCP service account
)
resp = client.chat.completions.create(
    model="gemini-3-flash",
    messages=[{"role": "user", "content": "Explain goroutines"}],
)

curl:

curl https://generativelanguage.googleapis.com/v1beta/openai/chat/completions \
  -H "Authorization: Bearer $GOOGLE_AI_STUDIO_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gemini-3-flash", "messages": [{"role": "user", "content": "hi"}]}'

Cursor and similar tools: paste the same base URL into the OpenAI base URL override field and the AI Studio key into the API key field — the same mechanics as any custom base URL in Cursor, with one Cursor-specific caveat: overriding the OpenAI base URL disables Cursor's built-in models (why that happens).

The three errors everyone hits

1. 404 Not Found — wrong path. The compatibility endpoint lives under /v1beta/openai/, not /v1beta/ or /v1/. If your client appends /chat/completions automatically, your base URL must end exactly at .../v1beta/openai/.

2. 404 model not found — OpenAI model name. Tools often default to gpt-4o or similar. Through this endpoint you must request Gemini models by their real names (gemini-3-pro, gemini-3-flash). If your tool hardcodes its model dropdown and won't accept custom names, the override can't work — that's a tool limitation, not an endpoint one.

3. 401 Unauthorized — wrong key type. The endpoint takes Google AI Studio API keys (the ones from aistudio.google.com). Vertex AI service-account credentials use a different auth flow and will not work as a bearer key here. Also check the usual suspect: an environment variable from a previous provider still winning over your new config (the double-env-var 401).

What you give up with a direct override

The override is free and official, but it's single-provider: every request goes to Gemini regardless of whether Gemini is the right model for it. You also take on Gemini-specific quirks (parameter support differs from OpenAI's API in places like penalties and logprobs) and you'll be editing base URLs again the next time you want to try another provider.

When a router is the cleaner setup

If the reason you're overriding base URLs is "I want cheaper/faster models for some calls" rather than "I specifically want only Gemini", a router gives you the same one-line config change but with every provider behind it: CodeRouter exposes one OpenAI-compatible endpoint, routes each request to the cheapest capable model (Gemini 3 Flash included — it's one of the best value models in the pool), and falls back automatically when a provider has a bad day. Same integration effort, no per-provider URL juggling — how phase-aware routing decides.

Related reading

Ready to Reduce Your AI API Costs?

CodeRouter routes every API call to the optimal model — automatically. Start saving today.

Get Started Free →

Get weekly AI cost optimization tips

Join 2,000+ developers saving on LLM costs