Gemini-compatible API
Use this page only when an existing application specifically requires the Gemini format. Otherwise, prefer the OpenAI SDK.
Request path
Section titled “Request path”Gemini puts the model ID and action in the URL:
POST https://omrouter.com/v1beta/models/{model}:generateContentUse the model name shown on the Pricing page. URL-encode the model name before placing it in the path; the Python example below already does this.
curl --silent --show-error \ "https://omrouter.com/v1beta/models/${OMROUTER_MODEL_ID}:generateContent" \ --header "x-goog-api-key: $OMROUTER_API_KEY" \ --header 'Content-Type: application/json' \ --data '{ "contents": [ { "role": "user", "parts": [ {"text": "Reply with one short sentence."} ] } ] }'Python with requests
Section titled “Python with requests”python -m pip install requestsimport osfrom urllib.parse import quote
import requests
model = quote(os.environ["OMROUTER_MODEL_ID"], safe="")response = requests.post( f"https://omrouter.com/v1beta/models/{model}:generateContent", headers={ "x-goog-api-key": os.environ["OMROUTER_API_KEY"], "Content-Type": "application/json", }, json={ "contents": [ { "role": "user", "parts": [{"text": "Reply with one short sentence."}], } ] }, timeout=120,)response.raise_for_status()print(response.json()["candidates"][0]["content"]["parts"][0]["text"])Authentication choice
Section titled “Authentication choice”Use the x-goog-api-key header. A key query parameter also works, but it puts the API key in the URL where browser history and logs can retain it.
SDK compatibility
Section titled “SDK compatibility”Google SDK support for custom API addresses varies by version. If the SDK can change its base URL, confirm that requests go to omrouter.com; otherwise, use the HTTP example on this page.
See Gemini generateContent for the request and response fields used here.