> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openp.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# generateContent

> POST /v1beta/models/{model}:generateContent — the Gemini native protocol

The Gemini native protocol, supporting multimodal input (image / PDF / audio / video) and function calling.

## Request

```bash theme={null}
curl "https://openp.ai/v1beta/models/gemini-3.1-pro-preview:generateContent" \
  -H "x-goog-api-key: $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [{"text": "Explain the Fourier transform"}]
      }
    ],
    "generationConfig": {
      "temperature": 0.7,
      "maxOutputTokens": 2048,
      "topP": 0.95
    }
  }'
```

### Path variables

| Variable  | Description                                    |
| --------- | ---------------------------------------------- |
| `{model}` | Gemini model ID, e.g. `gemini-3.1-pro-preview` |

### Main fields

| Field                               | Type    | Description                                      |
| ----------------------------------- | ------- | ------------------------------------------------ |
| `contents`                          | array   | Conversation content, `role` is `user` / `model` |
| `systemInstruction`                 | object  | System prompt                                    |
| `generationConfig.temperature`      | number  | 0-2                                              |
| `generationConfig.topP`             | number  |                                                  |
| `generationConfig.topK`             | integer |                                                  |
| `generationConfig.maxOutputTokens`  | integer | Maximum output                                   |
| `generationConfig.candidateCount`   | integer | 1-8                                              |
| `generationConfig.stopSequences`    | array   |                                                  |
| `generationConfig.responseMimeType` | string  | `application/json` enables structured output     |
| `generationConfig.responseSchema`   | object  | JSON Schema enforcement                          |
| `generationConfig.thinkingConfig`   | object  | `{ thinkingBudget: 8000 }`                       |
| `tools`                             | array   | Function / retrieval tools                       |
| `toolConfig`                        | object  | `function_calling_config`                        |
| `safetySettings`                    | array   | Safety filter levels                             |

### parts types

```json theme={null}
{"role": "user", "parts": [
  {"text": "Look at this image"},
  {"inline_data": {"mime_type": "image/png", "data": "<base64>"}},
  {"file_data": {"mime_type": "application/pdf", "file_uri": "https://..."}}
]}
```

## Response

```json theme={null}
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [{"text": "The Fourier transform is..."}]
      },
      "finishReason": "STOP",
      "index": 0,
      "safetyRatings": [...]
    }
  ],
  "promptFeedback": {"safetyRatings": [...]},
  "usageMetadata": {
    "promptTokenCount": 15,
    "candidatesTokenCount": 412,
    "totalTokenCount": 427,
    "cachedContentTokenCount": 0,
    "thoughtsTokenCount": 0
  }
}
```

`finishReason`: `STOP` / `MAX_TOKENS` / `SAFETY` / `RECITATION` / `OTHER`.

## Function calling

```json theme={null}
{
  "contents": [{"role": "user", "parts": [{"text": "Weather in Beijing"}]}],
  "tools": [{
    "functionDeclarations": [{
      "name": "get_weather",
      "description": "Get weather for a city",
      "parameters": {
        "type": "object",
        "properties": {"city": {"type": "string"}},
        "required": ["city"]
      }
    }]
  }]
}
```

The response includes a `functionCall`:

```json theme={null}
{
  "candidates": [{
    "content": {"role": "model", "parts": [
      {"functionCall": {"name": "get_weather", "args": {"city": "Beijing"}}}
    ]}
  }]
}
```

After executing, append a `functionResponse`:

```json theme={null}
{"role": "user", "parts": [{
  "functionResponse": {
    "name": "get_weather",
    "response": {"city": "Beijing", "temp": 18, "desc": "clear"}
  }
}]}
```

## Thinking mode

```json theme={null}
{
  "contents": [{"role": "user", "parts": [{"text": "Prove Goldbach's conjecture"}]}],
  "generationConfig": {
    "thinkingConfig": { "thinkingBudget": 8000 }
  }
}
```

Or use a model ID with the `-thinking` suffix: `gemini-2.5-pro-thinking`.

## Structured output

```json theme={null}
{
  "contents": [{"role": "user", "parts": [{"text": "Return a user JSON"}]}],
  "generationConfig": {
    "responseMimeType": "application/json",
    "responseSchema": {
      "type": "object",
      "properties": {
        "name": {"type": "string"},
        "age": {"type": "integer"}
      },
      "required": ["name", "age"]
    }
  }
}
```
