# gemini-3.1-pro-preview · API guide

Use the exact API model ID `gemini-3.1-pro-preview`. This guide describes the platform contract; check the live catalog before calling the model.

## Request example

The platform origin is filled in at build time. Set API_KEY to your server-side key before running.

```bash
curl "https://newrouters.com/v1beta/models/gemini-3.1-pro-preview:generateContent" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $API_KEY" \
  --data '{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Explain how an HTTP request works in three concise steps."
        }
      ]
    }
  ],
  "generationConfig": {
    "maxOutputTokens": 1024
  }
}'
```

## Protocol and response

This model uses the gemini protocol. Read its native response and usage fields; do not wrap the request in the media task input envelope.

Supported endpoint templates：

- `POST /v1beta/models/{model}:generateContent`
- `POST /v1beta/models/{model}:streamGenerateContent`
- `POST /v1/interactions`
- `POST /v1beta/interactions`

| Limit | Catalog value |
| --- | --- |
| Context tokens | 128000 |
| Maximum output tokens | 16384 |

For streaming, use the native protocol streaming option and parse its events; check supported capabilities in the live catalog.








<!-- official-reference:start -->
## Official sources and identity

Checked: 2026-09-27 · Platform model: `gemini-3.1-pro-preview` · Official reference: `gemini-3.1-pro-preview`

- [gemini-3.1-pro-preview official reference](https://ai.google.dev/gemini-api/docs/models/gemini-3.1-pro-preview)
- [Google GenerateContent API](https://ai.google.dev/api/generate-content)
<!-- official-reference:end -->

## Pricing and troubleshooting

Check current availability, contract and account pricing before integration. Keep request IDs and usage receipts when diagnosing errors. [Complete API reference](/docs/api)

## Request examples in other languages

### JavaScript

```javascript
const apiBaseUrl = "https://newrouters.com";
const apiKey = process.env.API_KEY;
if (!apiKey) throw new Error("Set API_KEY in your server environment");

const response = await fetch(apiBaseUrl + "/v1beta/models/gemini-3.1-pro-preview:generateContent", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-goog-api-key": apiKey
  },
  body: JSON.stringify({
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Explain how an HTTP request works in three concise steps."
        }
      ]
    }
  ],
  "generationConfig": {
    "maxOutputTokens": 1024
  }
})
});

const result = await response.json();
if (!response.ok) throw new Error(JSON.stringify(result));
console.log(result);
```

### Python

```python
import json
import os
from urllib.request import Request, urlopen

api_base_url = "https://newrouters.com"
api_key = os.environ["API_KEY"]
body = json.loads("{\"contents\":[{\"role\":\"user\",\"parts\":[{\"text\":\"Explain how an HTTP request works in three concise steps.\"}]}],\"generationConfig\":{\"maxOutputTokens\":1024}}")

request = Request(
    api_base_url + "/v1beta/models/gemini-3.1-pro-preview:generateContent",
    data=json.dumps(body).encode("utf-8"),
    headers={
    "Content-Type": "application/json",
    "x-goog-api-key": api_key
    },
    method="POST",
)
with urlopen(request) as response:
    print(json.load(response))
```

## Response fields (illustrative values)

### HTTP 200

```json
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "text": "..."
          }
        ]
      },
      "finishReason": "STOP"
    }
  ]
}
```


