# Gemini API

https://modelportal.ai/docs/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 to `https://modelportal.ai`; the SDK adds `/v1beta` itself.
- Send the key in the `x-goog-api-key` header, the `key` query parameter, or `Authorization: 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`.

```bash
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"}]}]}'
```

```python
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`; without `alt=sse` you get a JSON array.
- `generation_config`, `system_instruction`, and `max_output_tokens` and `candidate_count` inside 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-Preferences` header; see [Provider selection](/docs/provider-routing).
- Error bodies are `{"error": {"code", "message", "status"}}`, where `status` depends only on the HTTP status.

Endpoints and fields are in the [Gemini-compatible API reference](/docs/api-gemini).
