# gemini-3.8-flash · API 接入

API 模型 ID 为 `gemini-3.8-flash`。本文说明平台的实际契约，调用前请核对实时目录中的可用性。

## 请求示例

平台地址在构建时填入，运行前设置 API_KEY 为服务端密钥。

```bash
curl "https://newrouters.com/v1beta/models/gemini-3.8-flash: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
  }
}'
```

## 协议与响应

此模型使用 gemini 协议，读取其原生响应及 usage 字段，不使用媒体任务的 input 包装。

支持的端点模板：

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

| 限制 | 目录值 |
| --- | --- |
| 上下文 Token | 128000 |
| 最大输出 Token | 16384 |

流式调用使用该协议的原生流式选项，并按协议解析事件；能力以实时目录为准。








<!-- official-reference:start -->
## 官方来源与模型身份

核对日期: 2026-09-27 · 平台模型: `gemini-3.8-flash` · 官方对应: `gemini-3.8-flash`

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

## 计费与排错

接入时核对当前可用性、契约和账号价格。排错时保留请求 ID 与消费凭据。 [完整 API 参考](/zh/docs/api)

## 多语言请求示例

### 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.8-flash: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.8-flash: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))
```

## 响应字段节选（示意值）

### HTTP 200

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


