> For the complete documentation index, see [llms.txt](https://docs.fastrouter.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fastrouter.ai/api-reference/gemini-native-format.md).

# Gemini Native Format

## Generate Content (Gemini Format)

> Generates content using Google's native Gemini API format. This is a drop-in replacement for Google's \`generateContent\` endpoint — simply replace \`generativelanguage.googleapis.com\` with \`api.fastrouter.ai\` in your base URL and use your FastRouter API key.\
> \
> \*\*Full URL:\*\* \`POST <https://api.fastrouter.ai/v1/models/{model}:generateContent?key=YOUR\\_FASTROUTER\\_API\\_KEY\\`\\>
> \
> \*\*Authentication:\*\* Pass your FastRouter API key via the \`?key=YOUR\_API\_KEY\` query parameter (Google Gemini style).\
> \
> \*\*Request/Response format:\*\* Identical to Google's Gemini API. The request body uses \`contents\` (with \`parts\`) and \`generationConfig\`. The response includes \`candidates\` with generated content and \`usageMetadata\` with token counts.\
> \
> \*\*Cost tracking:\*\* The response \`usageMetadata\` object includes a \`cost\` field showing credits consumed.

```json
{"openapi":"3.1.0","info":{"title":"FastRouter API Reference","version":"1.0.0"},"tags":[{"name":"Gemini Native API","description":"Google Gemini native API format. Send requests using Google's native generateContent format with FastRouter authentication."}],"servers":[{"url":"https://api.fastrouter.ai","description":"Production API"}],"security":[{"keyQuery":[]}],"components":{"securitySchemes":{"keyQuery":{"type":"apiKey","in":"query","name":"key","description":"FastRouter API Key (Gemini style). Get yours at https://fastrouter.ai\n\nFormat: `?key=YOUR_API_KEY`"}},"responses":{"BadRequestError":{"description":"Bad Request - The request is malformed. This could be due to missing parameters, invalid formats, or routing errors.\n\n**Note:** the 400 body shape is not uniform. Validation errors return the structured object below, but routing/model errors may instead return a plain string: `{ \"error\": \"<message>\" }`. A few endpoints (e.g. some file operations) may return a plain-text body rather than JSON.","content":{"application/json":{"schema":{"oneOf":[{"type":"object","description":"Structured validation error.","properties":{"error":{"type":"object","properties":{"message":{"type":"string"},"type":{"type":"string"},"code":{"type":"string"}}}}},{"type":"object","description":"Plain-string routing/model error.","properties":{"error":{"type":"string"}}}]}}}},"UnauthorizedError":{"description":"Invalid Credentials - Your API key is invalid, missing, or disabled. Check your credentials.\n\nNote: the 401 error body uses `code`, `message`, `param`, and `type` (there is no `status` field), and `type` is `invalid_request_error`.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"object","properties":{"message":{"type":"string"},"type":{"type":"string"},"param":{"type":"string","nullable":true},"code":{"type":"string"}}}}}}}},"InsufficientCreditsError":{"description":"Insufficient Credits - Your account or API key has run out of credits. Add more credits and retry the request.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"object","properties":{"message":{"type":"string"},"type":{"type":"string"},"code":{"type":"string"},"status":{"type":"integer"}}}}}}}},"RateLimitError":{"description":"Rate Limited - You have exceeded your request limits (TPM/RPM). Slow down or increase your limits.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"object","properties":{"message":{"type":"string"},"type":{"type":"string"},"code":{"type":"string"},"status":{"type":"integer"}}}}}}}},"InternalServerError":{"description":"Internal Error - Something went wrong on our side. Retry the request, and contact support if the issue persists.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"object","properties":{"message":{"type":"string"},"type":{"type":"string"},"code":{"type":"string"},"status":{"type":"integer"}}}}}}}}}},"paths":{"/v1/models/{model}:generateContent":{"post":{"operationId":"geminiGenerateContent","tags":["Gemini Native API"],"summary":"Generate Content (Gemini Format)","description":"Generates content using Google's native Gemini API format. This is a drop-in replacement for Google's `generateContent` endpoint — simply replace `generativelanguage.googleapis.com` with `api.fastrouter.ai` in your base URL and use your FastRouter API key.\n\n**Full URL:** `POST https://api.fastrouter.ai/v1/models/{model}:generateContent?key=YOUR_FASTROUTER_API_KEY`\n\n**Authentication:** Pass your FastRouter API key via the `?key=YOUR_API_KEY` query parameter (Google Gemini style).\n\n**Request/Response format:** Identical to Google's Gemini API. The request body uses `contents` (with `parts`) and `generationConfig`. The response includes `candidates` with generated content and `usageMetadata` with token counts.\n\n**Cost tracking:** The response `usageMetadata` object includes a `cost` field showing credits consumed.","parameters":[{"name":"model","in":"path","required":true,"schema":{"type":"string"},"description":"The Gemini model ID to use (e.g. gemini-2.5-pro, gemini-2.5-flash)."},{"name":"key","in":"query","required":true,"schema":{"type":"string"},"description":"FastRouter API key (Gemini style: pass as query parameter)."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["contents"],"properties":{"contents":{"type":"array","description":"The conversation content to send to the model.","items":{"type":"object","properties":{"role":{"type":"string","enum":["user","model"],"description":"The role of the content author."},"parts":{"type":"array","description":"The parts of the content.","items":{"type":"object","properties":{"text":{"type":"string","description":"Text content."}}}}}}},"generationConfig":{"type":"object","description":"Configuration options for content generation.","properties":{"temperature":{"type":"number","description":"Controls randomness. Range: 0.0 to 2.0."},"topP":{"type":"number","description":"Nucleus sampling parameter."},"topK":{"type":"integer","description":"Top-K sampling parameter."},"maxOutputTokens":{"type":"integer","description":"Maximum number of tokens to generate."},"stopSequences":{"type":"array","description":"Sequences that will stop generation.","items":{"type":"string"}},"candidateCount":{"type":"integer","description":"Number of response candidates to generate."},"responseMimeType":{"type":"string","description":"MIME type of the response (e.g. application/json for JSON mode)."}}},"safetySettings":{"type":"array","description":"Safety settings to control content filtering.","items":{"type":"object","properties":{"category":{"type":"string","description":"The safety category.","enum":["HARM_CATEGORY_HARASSMENT","HARM_CATEGORY_HATE_SPEECH","HARM_CATEGORY_SEXUALLY_EXPLICIT","HARM_CATEGORY_DANGEROUS_CONTENT"]},"threshold":{"type":"string","description":"The blocking threshold.","enum":["BLOCK_NONE","BLOCK_LOW_AND_ABOVE","BLOCK_MEDIUM_AND_ABOVE","BLOCK_ONLY_HIGH"]}}}},"systemInstruction":{"type":"object","description":"System instruction for the model.","properties":{"parts":{"type":"array","items":{"type":"object","properties":{"text":{"type":"string","description":"System instruction text."}}}}}}}}}}},"responses":{"200":{"description":"Successful response with generated content.","content":{"application/json":{"schema":{"type":"object","properties":{"candidates":{"type":"array","items":{"type":"object","properties":{"content":{"type":"object","properties":{"parts":{"type":"array","items":{"type":"object","properties":{"text":{"type":"string"}}}},"role":{"type":"string"}}},"finishReason":{"type":"string"},"safetyRatings":{"type":"array","items":{"type":"object","properties":{"category":{"type":"string"},"probability":{"type":"string"}}}}}}},"usageMetadata":{"type":"object","properties":{"promptTokenCount":{"type":"integer"},"candidatesTokenCount":{"type":"integer"},"totalTokenCount":{"type":"integer"},"cost":{"type":"number","description":"Credits consumed for this request."}}},"modelVersion":{"type":"string"}}}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"402":{"$ref":"#/components/responses/InsufficientCreditsError"},"429":{"$ref":"#/components/responses/RateLimitError"},"500":{"$ref":"#/components/responses/InternalServerError"},"502":{"description":"Bad Gateway — failed to reach Google AI Studio.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"integer"},"message":{"type":"string"},"status":{"type":"string"}}}}}}}}}}}}}
```

## Stream Generate Content (Gemini Format)

> Generates content using Google's native Gemini API format with streaming. Returns Server-Sent Events (SSE) with incremental content chunks. This is a drop-in replacement for Google's \`streamGenerateContent\` endpoint.\
> \
> \*\*Full URL:\*\* \`POST <https://api.fastrouter.ai/v1/models/{model}:streamGenerateContent?key=YOUR\\_FASTROUTER\\_API\\_KEY\\`\\>
> \
> \*\*Authentication:\*\* Pass your FastRouter API key via the \`?key=YOUR\_API\_KEY\` query parameter (Google Gemini style).\
> \
> \*\*Streaming format:\*\* Returns SSE events with \`data:\` prefixed JSON objects. Each chunk contains partial \`candidates\` with generated content. The final chunk includes \`usageMetadata\` with token counts and a \`cost\` field.\
> \
> \*\*Cost tracking:\*\* The final streamed chunk's \`usageMetadata\` object includes a \`cost\` field showing credits consumed.

```json
{"openapi":"3.1.0","info":{"title":"FastRouter API Reference","version":"1.0.0"},"tags":[{"name":"Gemini Native API","description":"Google Gemini native API format. Send requests using Google's native generateContent format with FastRouter authentication."}],"servers":[{"url":"https://api.fastrouter.ai","description":"Production API"}],"security":[{"keyQuery":[]}],"components":{"securitySchemes":{"keyQuery":{"type":"apiKey","in":"query","name":"key","description":"FastRouter API Key (Gemini style). Get yours at https://fastrouter.ai\n\nFormat: `?key=YOUR_API_KEY`"}},"responses":{"BadRequestError":{"description":"Bad Request - The request is malformed. This could be due to missing parameters, invalid formats, or routing errors.\n\n**Note:** the 400 body shape is not uniform. Validation errors return the structured object below, but routing/model errors may instead return a plain string: `{ \"error\": \"<message>\" }`. A few endpoints (e.g. some file operations) may return a plain-text body rather than JSON.","content":{"application/json":{"schema":{"oneOf":[{"type":"object","description":"Structured validation error.","properties":{"error":{"type":"object","properties":{"message":{"type":"string"},"type":{"type":"string"},"code":{"type":"string"}}}}},{"type":"object","description":"Plain-string routing/model error.","properties":{"error":{"type":"string"}}}]}}}},"UnauthorizedError":{"description":"Invalid Credentials - Your API key is invalid, missing, or disabled. Check your credentials.\n\nNote: the 401 error body uses `code`, `message`, `param`, and `type` (there is no `status` field), and `type` is `invalid_request_error`.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"object","properties":{"message":{"type":"string"},"type":{"type":"string"},"param":{"type":"string","nullable":true},"code":{"type":"string"}}}}}}}},"InsufficientCreditsError":{"description":"Insufficient Credits - Your account or API key has run out of credits. Add more credits and retry the request.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"object","properties":{"message":{"type":"string"},"type":{"type":"string"},"code":{"type":"string"},"status":{"type":"integer"}}}}}}}},"RateLimitError":{"description":"Rate Limited - You have exceeded your request limits (TPM/RPM). Slow down or increase your limits.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"object","properties":{"message":{"type":"string"},"type":{"type":"string"},"code":{"type":"string"},"status":{"type":"integer"}}}}}}}},"InternalServerError":{"description":"Internal Error - Something went wrong on our side. Retry the request, and contact support if the issue persists.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"object","properties":{"message":{"type":"string"},"type":{"type":"string"},"code":{"type":"string"},"status":{"type":"integer"}}}}}}}}}},"paths":{"/v1/models/{model}:streamGenerateContent":{"post":{"operationId":"geminiStreamGenerateContent","tags":["Gemini Native API"],"summary":"Stream Generate Content (Gemini Format)","description":"Generates content using Google's native Gemini API format with streaming. Returns Server-Sent Events (SSE) with incremental content chunks. This is a drop-in replacement for Google's `streamGenerateContent` endpoint.\n\n**Full URL:** `POST https://api.fastrouter.ai/v1/models/{model}:streamGenerateContent?key=YOUR_FASTROUTER_API_KEY`\n\n**Authentication:** Pass your FastRouter API key via the `?key=YOUR_API_KEY` query parameter (Google Gemini style).\n\n**Streaming format:** Returns SSE events with `data:` prefixed JSON objects. Each chunk contains partial `candidates` with generated content. The final chunk includes `usageMetadata` with token counts and a `cost` field.\n\n**Cost tracking:** The final streamed chunk's `usageMetadata` object includes a `cost` field showing credits consumed.","parameters":[{"name":"model","in":"path","required":true,"schema":{"type":"string"},"description":"The Gemini model ID to use (e.g. gemini-2.5-pro, gemini-2.5-flash)."},{"name":"key","in":"query","required":true,"schema":{"type":"string"},"description":"FastRouter API key (Gemini style: pass as query parameter)."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["contents"],"properties":{"contents":{"type":"array","description":"The conversation content to send to the model.","items":{"type":"object","properties":{"role":{"type":"string","enum":["user","model"],"description":"The role of the content author."},"parts":{"type":"array","description":"The parts of the content.","items":{"type":"object","properties":{"text":{"type":"string","description":"Text content."}}}}}}},"generationConfig":{"type":"object","description":"Configuration options for content generation.","properties":{"temperature":{"type":"number","description":"Controls randomness. Range: 0.0 to 2.0."},"topP":{"type":"number","description":"Nucleus sampling parameter."},"topK":{"type":"integer","description":"Top-K sampling parameter."},"maxOutputTokens":{"type":"integer","description":"Maximum number of tokens to generate."},"stopSequences":{"type":"array","description":"Sequences that will stop generation.","items":{"type":"string"}}}},"safetySettings":{"type":"array","description":"Safety settings to control content filtering.","items":{"type":"object","properties":{"category":{"type":"string","enum":["HARM_CATEGORY_HARASSMENT","HARM_CATEGORY_HATE_SPEECH","HARM_CATEGORY_SEXUALLY_EXPLICIT","HARM_CATEGORY_DANGEROUS_CONTENT"]},"threshold":{"type":"string","enum":["BLOCK_NONE","BLOCK_LOW_AND_ABOVE","BLOCK_MEDIUM_AND_ABOVE","BLOCK_ONLY_HIGH"]}}}},"systemInstruction":{"type":"object","description":"System instruction for the model.","properties":{"parts":{"type":"array","items":{"type":"object","properties":{"text":{"type":"string","description":"System instruction text."}}}}}}}}}}},"responses":{"200":{"description":"Streaming response with Server-Sent Events containing generated content chunks.","content":{"text/event-stream":{"schema":{"type":"object","description":"Each SSE event contains a JSON object with partial candidates and usage metadata.","properties":{"candidates":{"type":"array","items":{"type":"object","properties":{"content":{"type":"object","properties":{"parts":{"type":"array","items":{"type":"object","properties":{"text":{"type":"string"}}}},"role":{"type":"string"}}},"finishReason":{"type":"string"}}}},"usageMetadata":{"type":"object","properties":{"promptTokenCount":{"type":"integer"},"candidatesTokenCount":{"type":"integer"},"totalTokenCount":{"type":"integer"},"cost":{"type":"number","description":"Credits consumed for this request."}}}}}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"402":{"$ref":"#/components/responses/InsufficientCreditsError"},"429":{"$ref":"#/components/responses/RateLimitError"},"500":{"$ref":"#/components/responses/InternalServerError"},"502":{"description":"Bad Gateway — failed to reach Google AI Studio.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"integer"},"message":{"type":"string"},"status":{"type":"string"}}}}}}}}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.fastrouter.ai/api-reference/gemini-native-format.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
