# Gemini Text Models (Native Format)

Brioi supports the native Google Gemini API format. Existing applications built with the Google Gen AI SDK, Gemini CLI, or direct `generateContent` HTTP calls can switch by pointing the base URL to Brioi and supplying a Brioi API key—no request body changes needed.

> **Use the native Gemini format documented here.** Although the OpenAI-compatible `POST /v1/chat/completions` endpoint can also invoke Gemini models, format translation may strip Gemini-specific fields such as `thinkingConfig`, `responseSchema`, and `thoughtSignature`. Use the OpenAI-compatible format only for clients that support solely OpenAI schemas and do not need those capabilities; use the native format for all new integrations.

## Endpoints

| Operation | Request |
|---|---|
| Non-streaming generation | `POST https://vip.brioi.com/v1beta/models/{model}:generateContent` |
| Streaming generation (SSE) | `POST https://vip.brioi.com/v1beta/models/{model}:streamGenerateContent?alt=sse` |
| List models | `GET https://vip.brioi.com/v1beta/models` |

Replace `{model}` with the model ID, such as `gemini-4-carbon`. Streaming is determined by the URL action, so no `stream` field is needed in the request body.

`:countTokens` is not supported and returns `404` (`Invalid URL`).

## Authentication

Any of the three methods below is accepted:

| Method | Example |
|---|---|
| `x-goog-api-key` header (Gemini SDK default) | `x-goog-api-key: YOUR_API_KEY` |
| `Authorization` header | `Authorization: Bearer YOUR_API_KEY` |
| `key` URL query parameter | `...:generateContent?key=YOUR_API_KEY` |

`YOUR_API_KEY` is your Brioi API key, not a Google API key. Because URL query parameters appear in access logs and browser history, prefer request headers for server-side calls.

## Available Models

Available models depend on your API key's assigned group. Query the live model list:

```bash
curl "https://vip.brioi.com/v1beta/models" \
  -H "x-goog-api-key: YOUR_API_KEY"
```

Returns the native Gemini model list format, where `models[].name` provides the model ID to substitute into `{model}` (for example, `gemini-4-carbon`).

## Request Body

The request body follows Google's official `GenerateContentRequest` schema. Common fields:

| Field | Type | Required | Description |
|---|---|---|---|
| `contents` | array | Yes | Ordered conversation turns. |
| `contents[].role` | string | No | `user` or `model`. Populate for multi-turn conversations. |
| `contents[].parts` | array | Yes | Content parts such as text or images. |
| `parts[].text` | string | Conditional | Text content (required when no media part is supplied). |
| `parts[].inlineData` | object | No | Base64-encoded inline file containing `mimeType` and `data`. |
| `parts[].fileData` | object | No | Publicly accessible direct `HTTPS` file or media URL containing `mimeType` and `fileUri`. |
| `systemInstruction` | object | No | System instructions using the `contents[]` item structure, e.g. `{"parts":[{"text":"..."}]}`. |
| `generationConfig` | object | No | Generation parameters such as `temperature`, `maxOutputTokens`, `responseMimeType`, `responseSchema`, and `thinkingConfig`. |
| `tools` | array | No | Tool declarations such as function calling. |

Pass additional fields per the [official Gemini API documentation](https://ai.google.dev/api/generate-content). Support for individual features depends on the target model.

## Examples

### Non-Streaming Request

```bash
curl -X POST "https://vip.brioi.com/v1beta/models/gemini-4-carbon:generateContent" \
  -H "x-goog-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "systemInstruction": {"parts": [{"text": "Reply concisely."}]},
    "contents": [
      {"role": "user", "parts": [{"text": "Explain what a vector database is in one sentence."}]}
    ],
    "generationConfig": {"maxOutputTokens": 1024}
  }'
```

The model's reply is in `candidates[0].content.parts[]`, and token usage is reported in `usageMetadata`.

Thinking models emit reasoning summary parts marked with `"thought": true` ahead of the final answer; read only `text` parts without the `thought` flag as the final answer. Some parts carry a `thoughtSignature`—in multi-turn conversations, pass the previous `model` turn's `parts` back verbatim. Reasoning tokens are counted in `usageMetadata.thoughtsTokenCount` and billed at the output rate.

### Streaming Request

```bash
curl -N -X POST "https://vip.brioi.com/v1beta/models/gemini-4-carbon:streamGenerateContent?alt=sse" \
  -H "x-goog-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {"role": "user", "parts": [{"text": "Write a short four-line poem."}]}
    ]
  }'
```

Returns SSE where each `data:` line is a `GenerateContentResponse` chunk. Concatenate `parts[].text` in order across chunks while skipping `thought` parts. Omitting `?alt=sse` currently also streams SSE, but we recommend keeping `?alt=sse` per the official Gemini convention.

### Structured Outputs (JSON)

To enforce a strict JSON output schema, set both `responseMimeType` and `responseSchema` in `generationConfig` (no format instructions needed in the prompt):

```bash
curl -X POST "https://vip.brioi.com/v1beta/models/gemini-4-hydrogen:generateContent" \
  -H "x-goog-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"parts": [{"text": "What is the capital of France?"}]}],
    "generationConfig": {
      "responseMimeType": "application/json",
      "responseSchema": {
        "type": "object",
        "properties": {"city": {"type": "string"}},
        "required": ["city"]
      }
    }
  }'
```

The response text is a JSON string such as `{"city":"Paris"}`. Extract it the same way as a standard request: skip `thought` parts, concatenate the remaining `parts[].text`, and parse as JSON. Passing `responseMimeType` without `responseSchema` also returns JSON, with property names chosen by the model. Structured outputs are guaranteed only on the native Gemini format.

### Multi-Turn Conversation

```json
{
  "contents": [
    {"role": "user", "parts": [{"text": "My name is Alex."}]},
    {"role": "model", "parts": [{"text": "Hello, Alex."}]},
    {"role": "user", "parts": [{"text": "What is my name?"}]}
  ]
}
```

## Using with SDKs & CLI

### Google Gen AI SDK (Python)

```python
from google import genai

client = genai.Client(
    api_key="YOUR_API_KEY",
    http_options={"base_url": "https://vip.brioi.com"},
)
resp = client.models.generate_content(
    model="gemini-4-carbon",
    contents="Explain what a vector database is in one sentence.",
)
print(resp.text)
```

### Google Gen AI SDK (JavaScript / TypeScript)

```javascript
import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({
  apiKey: "YOUR_API_KEY",
  httpOptions: { baseUrl: "https://vip.brioi.com" },
});
const resp = await ai.models.generateContent({
  model: "gemini-4-carbon",
  contents: "Explain what a vector database is in one sentence.",
});
console.log(resp.text)
```

### Gemini CLI

```bash
export GEMINI_API_KEY="YOUR_API_KEY"
export GOOGLE_GEMINI_BASE_URL="https://vip.brioi.com"
gemini -m gemini-4-carbon
```

On first launch, select **Use Gemini API Key** (do not choose Google account login or Vertex AI). Setting environment variables alone without having selected an auth method causes the CLI to report `Invalid auth method selected.`; write the following to `~/.gemini/settings.json` or run `/auth` inside the CLI:

```json
{
  "security": {
    "auth": { "selectedType": "gemini-api-key" }
  }
}
```

For non-interactive script runs via `gemini -p "..."`, trust the working directory beforehand or pass `--skip-trust`.

Set Base URL strictly to `https://vip.brioi.com` without `/v1beta`—the SDK appends the version path automatically.

## Troubleshooting

**Returns `401` or invalid token:** Verify that you are passing a Brioi API key rather than a Google API key.

**Returns `400` `"Request contains an invalid argument"`:** The payload contains a field or value unsupported by the target model (commonly invalid `thinkingConfig`, `responseSchema`, or `tools`). Test with `contents` only first, then re-introduce optional fields one by one.

**`thinkingConfig` or `responseSchema` has no effect via OpenAI-compatible format:** Protocol conversion can drop Gemini-specific fields. Switch to the native Gemini format on this page.

**Plain text returned despite passing `responseSchema`:** Confirm you are calling the native endpoint and that `responseMimeType` is `application/json` with both fields placed inside `generationConfig`. If it still reproduces, provide the model ID, timestamp, and `X-Oneapi-Request-Id` from the response.

**`countTokens` returns `404`:** Not currently supported; read token usage from `usageMetadata` in generation responses.

**Reasoning summary appears mixed into the answer:** Filter out parts marked with `"thought": true` when rendering the response (see **Non-Streaming Request** above).

