---
title: "Generate content (Gemini format)"
description: "Serves Google's `generateContent`: set the Google GenAI SDK's base URL to `https://gateway.respan.ai` and pass your Respan key as its key. Requests are routed by model, so a model from another provider answers in Gemini's shape; Gemini-only fields such as `safetySettings`, `cachedContent` and `googleSearch` reach Gemini models and are refused with `400` for others. To stream, call `:streamGenerateContent?alt=sse` on the same path. Respan params go in `X-Data-Respan-Params`, a top-level `respan_params`, or `metadata.respan_params`."
---

**POST** `https://gateway.respan.ai/v1beta/models/{model}:generateContent`

Serves Google's `generateContent`: set the Google GenAI SDK's base URL to `https://gateway.respan.ai` and pass your Respan key as its key. Requests are routed by model, so a model from another provider answers in Gemini's shape; Gemini-only fields such as `safetySettings`, `cachedContent` and `googleSearch` reach Gemini models and are refused with `400` for others. To stream, call `:streamGenerateContent?alt=sse` on the same path. Respan params go in `X-Data-Respan-Params`, a top-level `respan_params`, or `metadata.respan_params`.

## Servers

`https://gateway.respan.ai`: Respan gateway

## Authentication

### RespanApiKey

Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer &lt;RESPAN_API_KEY&gt;. For /api/responses, provider credentials such as Perplexity, OpenAI, or Azure OpenAI go in Settings -&gt; Providers or respan_params.credential_override in the request body, not in this authentication field.

HTTP scheme: `bearer`; format: `Respan API key`.


```http
Authorization: Bearer $RESPAN_API_KEY
```


## Headers


| Parameter | Type | Required | Description and constraints |
| --- | --- | --- | --- |
| `x-goog-api-key` | `string` | Optional | Your Respan API key, as the Google GenAI SDK sends it. `Authorization: Bearer` also works.<br />Example: `"YOUR_RESPAN_API_KEY"` |
| `X-Data-Respan-Params` | `string` | Optional | Base64-encoded JSON object of Respan parameters. Use it for form uploads, which have no JSON body. |


## Path parameters


| Parameter | Type | Required | Description and constraints |
| --- | --- | --- | --- |
| `model` | `string` | Required | A model ID from the catalog. Prefix a provider to pin it, such as `vertex_ai/gemini-2.5-pro`.<br />Example: `"gemini-2.5-flash"` |


## Request body

A request body is required.

### application/json


| Field | Type | Requirement | Description and constraints |
| --- | --- | --- | --- |
| `$` | `object` | Required body | Additional properties are allowed |
| `contents` | `array<object>` | Required in parent | The conversation, as Gemini `Content` objects with `role` and `parts`. |
| `contents[]` | `object` | Array item | Additional properties are allowed |
| `systemInstruction` | `object` | Optional | Additional properties are allowed |
| `generationConfig` | `object` | Optional | Sampling, output limits, thinking and structured output (`responseMimeType`, `responseJsonSchema`).<br />Additional properties are allowed |
| `tools` | `array<object>` | Optional | Function tools in `functionDeclarations`, or Google-run tools (Gemini models only). |
| `tools[]` | `object` | Array item | Additional properties are allowed |
| `toolConfig` | `object` | Optional | Additional properties are allowed |
| `safetySettings` | `array<object>` | Optional | Gemini models only. |
| `safetySettings[]` | `object` | Array item | Additional properties are allowed |
| `cachedContent` | `string` | Optional | Gemini models only. |
| `respan_params` | `object` | Optional | Additional properties are allowed |


<details class="api-schema-source">
<summary>OpenAPI request schema</summary>


```json
{
  "type": "object",
  "required": [
    "contents"
  ],
  "additionalProperties": true,
  "properties": {
    "contents": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true
      },
      "description": "The conversation, as Gemini `Content` objects with `role` and `parts`."
    },
    "systemInstruction": {
      "type": "object",
      "additionalProperties": true
    },
    "generationConfig": {
      "type": "object",
      "additionalProperties": true,
      "description": "Sampling, output limits, thinking and structured output (`responseMimeType`, `responseJsonSchema`)."
    },
    "tools": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true
      },
      "description": "Function tools in `functionDeclarations`, or Google-run tools (Gemini models only)."
    },
    "toolConfig": {
      "type": "object",
      "additionalProperties": true
    },
    "safetySettings": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true
      },
      "description": "Gemini models only."
    },
    "cachedContent": {
      "type": "string",
      "description": "Gemini models only."
    },
    "respan_params": {
      "type": "object",
      "additionalProperties": true
    }
  }
}
```

</details>

##### Example


```json
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Reply with exactly ok."
        }
      ]
    }
  ],
  "generationConfig": {
    "maxOutputTokens": 128,
    "thinkingConfig": {
      "thinkingLevel": "low"
    }
  }
}
```


## Examples

### Generate content

#### Headers


```json
{
  "x-goog-api-key": "YOUR_RESPAN_API_KEY"
}
```


#### Path parameters


```json
{
  "model": "gemini-2.5-flash"
}
```


#### Request


```json
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Reply with exactly ok."
        }
      ]
    }
  ],
  "generationConfig": {
    "maxOutputTokens": 128,
    "thinkingConfig": {
      "thinkingLevel": "low"
    }
  }
}
```


#### Response


```json
{
  "body": {
    "candidates": [
      {
        "content": {
          "role": "model",
          "parts": [
            {
              "text": "AI learns patterns from data to make predictions and generate responses."
            }
          ]
        },
        "finishReason": "STOP",
        "index": 0
      }
    ]
  }
}
```


#### cURL


```bash
curl --request POST 'https://gateway.respan.ai/v1beta/models/gemini-2.5-flash:generateContent' \
  --header "Authorization: Bearer $RESPAN_API_KEY" \
  --header 'x-goog-api-key: YOUR_RESPAN_API_KEY' \
  --header 'Content-Type: application/json' \
  --data @- <<'JSON'
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Reply with exactly ok."
        }
      ]
    }
  ],
  "generationConfig": {
    "maxOutputTokens": 128,
    "thinkingConfig": {
      "thinkingLevel": "low"
    }
  }
}
JSON
```


<details>
<summary>Python</summary>



```python
import json
import os
import urllib.request

payload = json.loads(r'''{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Reply with exactly ok."
        }
      ]
    }
  ],
  "generationConfig": {
    "maxOutputTokens": 128,
    "thinkingConfig": {
      "thinkingLevel": "low"
    }
  }
}''')

request = urllib.request.Request(
    "https://gateway.respan.ai/v1beta/models/gemini-2.5-flash:generateContent",
    data=json.dumps(payload).encode(),
    headers={
        "Authorization": f"Bearer {os.environ['RESPAN_API_KEY']}",
        "Content-Type": "application/json",
        "x-goog-api-key": "YOUR_RESPAN_API_KEY",
    },
    method="POST",
)
with urllib.request.urlopen(request) as response:
    print(response.read().decode())
```


</details>

<details>
<summary>TypeScript</summary>



```typescript
const response = await fetch("https://gateway.respan.ai/v1beta/models/gemini-2.5-flash:generateContent", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.RESPAN_API_KEY}`,
    "Content-Type": "application/json",
    "x-goog-api-key": "YOUR_RESPAN_API_KEY",
  },
  body: JSON.stringify({
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "Reply with exactly ok."
          }
        ]
      }
    ],
    "generationConfig": {
      "maxOutputTokens": 128,
      "thinkingConfig": {
        "thinkingLevel": "low"
      }
    }
  }),
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.text());
```


</details>

## Responses

### 200

A `GenerateContentResponse`.

#### Response headers


| Parameter | Type | Required | Description and constraints |
| --- | --- | --- | --- |
| `X-Respan-Log-Id` | `string` | Optional | ID of the Respan log for this call. |
| `X-Respan-Gateway-Request-Id` | `string` | Optional | ID of the whole gateway request, on every log row it writes. |


#### application/json


| Field | Type | Requirement | Description and constraints |
| --- | --- | --- | --- |
| `$` | `object` | Body | Additional properties are allowed |
| `candidates` | `array<object>` | Optional | - |
| `candidates[]` | `object` | Array item | Additional properties are allowed |
| `usageMetadata` | `object` | Optional | Additional properties are allowed |


<details class="api-schema-source">
<summary>OpenAPI response schema</summary>


```json
{
  "type": "object",
  "additionalProperties": true,
  "properties": {
    "candidates": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true
      }
    },
    "usageMetadata": {
      "type": "object",
      "additionalProperties": true
    }
  }
}
```

</details>

##### Example


```json
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "text": "AI learns patterns from data to make predictions and generate responses."
          }
        ]
      },
      "finishReason": "STOP",
      "index": 0
    }
  ]
}
```


### 400

Invalid request, or a Gemini-only field sent to another provider's model.

#### application/json


| Field | Type | Requirement | Description and constraints |
| --- | --- | --- | --- |
| `$` | `object` | Body | Additional properties are allowed |


<details class="api-schema-source">
<summary>OpenAPI response schema</summary>


```json
{
  "type": "object",
  "additionalProperties": true
}
```

</details>

### 403

The API key is missing, invalid or expired.

#### application/json


| Field | Type | Requirement | Description and constraints |
| --- | --- | --- | --- |
| `$` | `object` | Body | - |
| `error` | `object` | Optional | - |
| `error.code` | `integer` | Optional | - |
| `error.message` | `string` | Optional | - |
| `error.status` | `string` | Optional | - |


<details class="api-schema-source">
<summary>OpenAPI response schema</summary>


```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "type": "integer"
        },
        "message": {
          "type": "string"
        },
        "status": {
          "type": "string"
        }
      }
    }
  }
}
```

</details>

##### Example


```json
{
  "error": {
    "code": 403,
    "message": "Your API key is invalid or expired, please check your API key in the platform settings.",
    "status": "PERMISSION_DENIED"
  }
}
```


## OpenAPI source

The operation and referenced components below retain the complete OpenAPI definitions, including constraints and examples.

<!-- openapi-operation:start -->
<details class="api-schema-source">
<summary>OpenAPI operation</summary>


```json
{
  "summary": "Generate content (Gemini format)",
  "operationId": "generateGeminiContent",
  "tags": [
    "Gateway"
  ],
  "description": "Serves Google's `generateContent`: set the Google GenAI SDK's base URL to `https://gateway.respan.ai` and pass your Respan key as its key. Requests are routed by model, so a model from another provider answers in Gemini's shape; Gemini-only fields such as `safetySettings`, `cachedContent` and `googleSearch` reach Gemini models and are refused with `400` for others. To stream, call `:streamGenerateContent?alt=sse` on the same path. Respan params go in `X-Data-Respan-Params`, a top-level `respan_params`, or `metadata.respan_params`.",
  "servers": [
    {
      "url": "https://gateway.respan.ai",
      "description": "Respan gateway"
    }
  ],
  "security": [
    {
      "RespanApiKey": []
    }
  ],
  "parameters": [
    {
      "name": "model",
      "in": "path",
      "required": true,
      "schema": {
        "type": "string"
      },
      "description": "A model ID from the catalog. Prefix a provider to pin it, such as `vertex_ai/gemini-2.5-pro`.",
      "example": "gemini-2.5-flash"
    },
    {
      "name": "x-goog-api-key",
      "in": "header",
      "required": false,
      "schema": {
        "type": "string"
      },
      "description": "Your Respan API key, as the Google GenAI SDK sends it. `Authorization: Bearer` also works.",
      "example": "YOUR_RESPAN_API_KEY"
    },
    {
      "name": "X-Data-Respan-Params",
      "in": "header",
      "required": false,
      "schema": {
        "type": "string"
      },
      "description": "Base64-encoded JSON object of Respan parameters. Use it for form uploads, which have no JSON body."
    }
  ],
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "required": [
            "contents"
          ],
          "additionalProperties": true,
          "properties": {
            "contents": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": true
              },
              "description": "The conversation, as Gemini `Content` objects with `role` and `parts`."
            },
            "systemInstruction": {
              "type": "object",
              "additionalProperties": true
            },
            "generationConfig": {
              "type": "object",
              "additionalProperties": true,
              "description": "Sampling, output limits, thinking and structured output (`responseMimeType`, `responseJsonSchema`)."
            },
            "tools": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": true
              },
              "description": "Function tools in `functionDeclarations`, or Google-run tools (Gemini models only)."
            },
            "toolConfig": {
              "type": "object",
              "additionalProperties": true
            },
            "safetySettings": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": true
              },
              "description": "Gemini models only."
            },
            "cachedContent": {
              "type": "string",
              "description": "Gemini models only."
            },
            "respan_params": {
              "type": "object",
              "additionalProperties": true
            }
          }
        },
        "example": {
          "contents": [
            {
              "role": "user",
              "parts": [
                {
                  "text": "Reply with exactly ok."
                }
              ]
            }
          ],
          "generationConfig": {
            "maxOutputTokens": 128,
            "thinkingConfig": {
              "thinkingLevel": "low"
            }
          }
        }
      }
    }
  },
  "responses": {
    "200": {
      "description": "A `GenerateContentResponse`.",
      "headers": {
        "X-Respan-Log-Id": {
          "description": "ID of the Respan log for this call.",
          "schema": {
            "type": "string"
          }
        },
        "X-Respan-Gateway-Request-Id": {
          "description": "ID of the whole gateway request, on every log row it writes.",
          "schema": {
            "type": "string"
          }
        }
      },
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "additionalProperties": true,
            "properties": {
              "candidates": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": true
                }
              },
              "usageMetadata": {
                "type": "object",
                "additionalProperties": true
              }
            }
          },
          "example": {
            "candidates": [
              {
                "content": {
                  "role": "model",
                  "parts": [
                    {
                      "text": "AI learns patterns from data to make predictions and generate responses."
                    }
                  ]
                },
                "finishReason": "STOP",
                "index": 0
              }
            ]
          }
        }
      }
    },
    "400": {
      "description": "Invalid request, or a Gemini-only field sent to another provider's model.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "additionalProperties": true
          }
        }
      }
    },
    "403": {
      "description": "The API key is missing, invalid or expired.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "error": {
                "type": "object",
                "properties": {
                  "code": {
                    "type": "integer"
                  },
                  "message": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string"
                  }
                }
              }
            }
          },
          "example": {
            "error": {
              "code": 403,
              "message": "Your API key is invalid or expired, please check your API key in the platform settings.",
              "status": "PERMISSION_DENIED"
            }
          }
        }
      }
    }
  },
  "x-fern-examples": [
    {
      "name": "Generate content",
      "headers": {
        "x-goog-api-key": "YOUR_RESPAN_API_KEY"
      },
      "path-parameters": {
        "model": "gemini-2.5-flash"
      },
      "request": {
        "contents": [
          {
            "role": "user",
            "parts": [
              {
                "text": "Reply with exactly ok."
              }
            ]
          }
        ],
        "generationConfig": {
          "maxOutputTokens": 128,
          "thinkingConfig": {
            "thinkingLevel": "low"
          }
        }
      },
      "response": {
        "body": {
          "candidates": [
            {
              "content": {
                "role": "model",
                "parts": [
                  {
                    "text": "AI learns patterns from data to make predictions and generate responses."
                  }
                ]
              },
              "finishReason": "STOP",
              "index": 0
            }
          ]
        }
      }
    }
  ]
}
```

</details>
<!-- openapi-operation:end -->

<!-- openapi-path-item:start -->
<details class="api-schema-source">
<summary>OpenAPI path metadata</summary>


```json
{}
```

</details>
<!-- openapi-path-item:end -->

<!-- openapi-components:start -->
<details class="api-schema-source">
<summary>Referenced OpenAPI components</summary>


```json
{
  "securitySchemes": {
    "RespanApiKey": {
      "type": "http",
      "scheme": "bearer",
      "bearerFormat": "Respan API key",
      "description": "Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer <RESPAN_API_KEY>. For /api/responses, provider credentials such as Perplexity, OpenAI, or Azure OpenAI go in Settings -> Providers or respan_params.credential_override in the request body, not in this authentication field.",
      "x-fern-bearer": {
        "name": "respanApiKey",
        "env": "RESPAN_API_KEY"
      }
    }
  }
}
```

</details>
<!-- openapi-components:end -->
