Skip to main content

Google AI Studio

Route your Google AI Studio / Gemini API calls through AI SpendOps for automatic usage tracking and cost attribution.

Configuration

SettingValue
Route/v1/google/*
Upstreamhttps://generativelanguage.googleapis.com
Auth headerAuthorization: Bearer ... or x-goog-api-key: ...
Streaming usageAuto-injected (stream_options.include_usage)

SDK base URL

https://proxy.aispendops.com/v1/google

Example

curl https://proxy.aispendops.com/v1/google/v1beta/openai/chat/completions \
-H "Authorization: Bearer your-google-api-key" \
-H "X-ASO-API-Key: aso_k_yourkey.secret" \
-H "Content-Type: application/json" \
-d '{"model":"gemini-2.0-flash","messages":[{"role":"user","content":"Hello"}]}'

Python SDK

from openai import OpenAI

client = OpenAI(
api_key="your-google-api-key",
base_url="https://proxy.aispendops.com/v1/google/v1beta/openai",
default_headers={"X-ASO-API-Key": "aso_k_yourkey.secret"},
)

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

Usage fields

FieldDescription
promptTokenCountInput tokens
candidatesTokenCountOutput tokens
totalTokenCountTotal tokens
cachedContentTokenCountTokens served from cached content
thoughtsTokenCountTokens used for thinking (via usageMetadata)

Notes

  • Google AI Studio supports both Authorization: Bearer and x-goog-api-key for authentication.
  • The proxy auto-injects stream_options: { include_usage: true } for streaming requests via the OpenAI-compatible endpoint.
  • Usage metadata is returned in a usageMetadata object in Google's native response format.