Gemini API
The Gemini-compatible API keeps the REST paths and request bodies of the Google Gemini API, so you can call catalog models with the Google GenAI SDK or plain HTTP.
Connecting
- The REST prefix is
https://modelportal.ai/v1beta. For the Google GenAI SDK, set base_url tohttps://modelportal.ai; the SDK adds/v1betaitself. - Send the key in the
x-goog-api-keyheader, thekeyquery parameter, orAuthorization: Bearer. If you use more than one, they must match. - The model ID goes in the path; write its slash as is or as
%2F.
curl "https://modelportal.ai/v1beta/models/MODEL_ID:generateContent" \
-H "x-goog-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"contents": [{"role": "user", "parts": [{"text": "Hello"}]}]}'
from google import genai
from google.genai import types
client = genai.Client(
api_key="YOUR_API_KEY",
http_options=types.HttpOptions(base_url="https://modelportal.ai"),
)
reply = client.models.generate_content(model="MODEL_ID", contents="Hello")
print(reply.text)
Differences from the OpenAI format
- Stream with
:streamGenerateContent?alt=sse; withoutalt=sseyou get a JSON array. generation_config,system_instruction, andmax_output_tokensandcandidate_countinside them, are converted to camelCase; sending both spellings of one field is rejected.- Without
maxOutputTokens, the platform fills in a value from the model's output limit and your available balance. - Pass routing preferences in the
X-ModelPortal-Provider-Preferencesheader; see Provider selection. - Error bodies are
{"error": {"code", "message", "status"}}, wherestatusdepends only on the HTTP status.
Endpoints and fields are in the Gemini-compatible API reference.