> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/gemini-3-1-flash-lite.md).

# Gemini 3.1 Flash Lite

> **Gemini 3.1 Flash Lite** 截至2026年3月，它是谷歌最便宜、最快的生产模型，于2026年3月3日发布。它是 Gemini 3.1 系列中面向 API 优化的层级——专为实时聊天机器人、分类流水线和 RAG 检索层等高吞吐、成本敏感型工作负载而设计。可通过 Ollama 或 Clore.ai 上的 vLLM 在 GPU 上自托管，以实现最大的成本控制。

## 什么是 Gemini 3.1 Flash Lite？

于2026年3月3日发布，作为 Gemini 3.1 系列的轻量入门版本（该系列还包括2026年2月19日发布的 Gemini 3.1 Pro），Flash Lite 以牺牲一定推理深度为代价，换来大幅降低的延迟和成本。它是谷歌对“又快又便宜”层级的回应——在性价比上直接与 GPT-5.4 的 mini 变体和 Claude Sonnet 竞争。

**主要规格：**

* **多模态**：文本、图像、音频、视频输入
* **上下文窗口**：100万 tokens（与 Gemini 3.1 Pro 相同）
* **输出**：每个请求最多 8K tokens
* **延迟**：短提示词首 token 时间约 120ms（API）
* **架构**：通过 speculative decoding 从 Gemini 3.1 Pro 蒸馏而来

> **注意：** Gemini 3.1 Flash Lite 是一个 **仅限 Google API 的** 模型——权重未公开发布。本指南涵盖：(a) 在 Clore.ai 基础设施上使用 Google Gemini API；以及 (b) 可完全自托管的类似开源替代方案。

## 方案 A：在 Clore.ai 服务器上使用 Gemini 3.1 Flash Lite API

即使你无法在本地运行权重，把你的 API 消费型应用托管在 Clore.ai 的廉价服务器上，对于长时间运行的进程、自动化流水线和批处理任务来说也很合理。

### 设置：在 Clore.ai 上部署 API 代理 + FastAPI

```bash
# 在 Clore.ai 上租用一台 CPU 或轻量 GPU 服务器
# RTX 3060（$0.03–0.07/小时）对于 API 代理工作负载已经绰绰有余

pip install google-generativeai fastapi uvicorn

cat > gemini_proxy.py << 'EOF'
import google.generativeai as genai
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import os

genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
model = genai.GenerativeModel("gemini-3.1-flash-lite")

app = FastAPI(title="Gemini 3.1 Flash Lite 代理")

class ChatRequest(BaseModel):
    message: str
    system_prompt: str = "你是一个乐于助人的助手。"
    max_tokens: int = 2048

@app.post("/chat")
async def chat(req: ChatRequest):
    try:
        response = model.generate_content(
            [req.system_prompt, req.message],
            generation_config=genai.GenerationConfig(
                max_output_tokens=req.max_tokens,
                temperature=0.7
            )
        )
        return {"response": response.text, "model": "gemini-3.1-flash-lite"}
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

@app.post("/vision")
async def vision_chat(image_url: str, prompt: str):
    import httpx
    async with httpx.AsyncClient() as client:
        img_data = await client.get(image_url)
    
    import PIL.Image
    import io
    image = PIL.Image.open(io.BytesIO(img_data.content))
    response = model.generate_content([prompt, image])
    return {"response": response.text}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8080)
EOF

GOOGLE_API_KEY=your-key uvicorn gemini_proxy:app --host 0.0.0.0 --port 8080
```

### 高吞吐批处理

```python
import google.generativeai as genai
import asyncio
from typing import List

genai.configure(api_key="YOUR_API_KEY")

async def batch_classify(texts: List[str], batch_size: int = 50) -> List[str]:
    """并行批量对文本进行分类——每 1000 条文本成本约 $0.001。"""
    model = genai.GenerativeModel("gemini-3.1-flash-lite")
    
    results = []
    for i in range(0, len(texts), batch_size):
        batch = texts[i:i + batch_size]
        tasks = [
            model.generate_content_async(
                f"将这段文本分类为 POSITIVE、NEGATIVE 或 NEUTRAL。只回复一个词。\n\n文本：{text}"
            )
            for text in batch
        ]
        responses = await asyncio.gather(*tasks, return_exceptions=True)
        results.extend([
            r.text.strip() if not isinstance(r, Exception) else "ERROR"
            for r in responses
        ])
    return results

# 示例
texts = ["Great product!", "Terrible service.", "It's okay I guess."]
labels = asyncio.run(batch_classify(texts))
print(list(zip(texts, labels)))
```

## 方案 B：开源替代方案（在 Clore.ai 上自托管）

如果你想要完全本地推理且没有 API 成本，这些模型在“快/便宜”层级上可与 Gemini 3.1 Flash Lite 匹配：

### Gemma 3 4B（谷歌的开源轻量模型）

```bash
# 可在任何拥有 6GB+ 显存的 GPU 上运行——甚至是 RTX 3060
docker run --gpus all -d \
  -p 11434:11434 \
  -v ollama_data:/root/.ollama \
  ollama/ollama

docker exec -it $(docker ps -q) ollama pull gemma3:4b
docker exec -it $(docker ps -q) ollama run gemma3:4b "简单解释一下量子纠缠。"
```

### Qwen3.5 7B（更快，且在相同规模下质量更高）

```bash
docker exec -it $(docker ps -q) ollama pull qwen3.5:7b
# 约 3.8GB 显存，在 RTX 3080 上约 45 tok/s
```

### Clore.ai 硬件上的速度对比

| 模型                         | 显存   | 每秒 tokens（RTX 4090，单流） | 每 100 万输出 tokens 成本                  |
| -------------------------- | ---- | ---------------------- | ------------------------------------ |
| Gemini 3.1 Flash Lite（API） | 不适用  | \~200（API）             | 每 100 万 tokens 约 $0.25 输入 / $1.50 输出 |
| Gemma 3 4B（本地）             | 4GB  | 95 tok/s               | 约 $0.58（RTX 4090，$0.20/小时）           |
| Qwen3.5 7B（本地）             | 8GB  | 78 tok/s               | \~$0.71                              |
| Gemma 3 12B（本地）            | 12GB | 55 tok/s               | \~$1.01                              |
| Gemma 3 27B（本地）            | 20GB | 32 tok/s               | \~$1.74                              |

> **结论：** 如果一次只处理一个请求，自托管的成本大致与 API 相当。优势来自 **批处理**：使用 vLLM 或 SGLang 提供并发请求服务时，同一张 4090 上的总吞吐量会提升数倍，每百万 tokens 的成本也会随之下降。若你有稳定、并行的大量请求，就自托管；若流量是突发且量小，就用 API。

## 在 Clore.ai 上部署

### 适合 Flash Lite 层级工作负载的推荐 GPU

| 使用场景         | 推荐 GPU          | Clore.ai 上的价格     |
| ------------ | --------------- | ----------------- |
| API 代理 / 自动化 | 无需 GPU（CPU 服务器） | 约 $0.05/小时        |
| 本地 4B 模型     | RTX 3060 12GB   | $0.03–0.07/小时     |
| 本地 7B 模型     | RTX 3080 10GB   | $0.05–0.19/小时     |
| 本地 27B 模型    | RTX 4090 24GB   | $0.14–0.42/小时（现货） |

### 在 Clore.ai 上一键启动 Ollama

在 Clore.ai 仪表板中，选择 **Ollama** 以下模板中的

```bash
# 或通过 SSH 手动操作：
curl -fsSL https://ollama.com/install.sh | sh
ollama serve &
ollama pull gemma3:4b
ollama run gemma3:4b
```

## 最适合 Flash Lite 层级的使用场景

1. **RAG 检索层** — 快速上下文排序，而不是最终生成
2. **实时聊天机器人回复** — 短查询低于200ms
3. **文档分类** — 每分钟处理数千份文档
4. **代码自动补全** — 低延迟建议生成
5. **翻译流水线** — 以低成本批量翻译内容
6. **内容审核** — 大规模分类用户内容

## 成本估算器

| 月度用量         | Google API 成本 | Clore.ai（Gemma 3 4B）        |
| ------------ | ------------- | --------------------------- |
| 1000万 tokens | \~$8.75       | 约 $3.60（月 50 小时运行 RTX 3060） |
| 1亿 tokens    | \~$7.00       | 约 $3.60（持续运行）               |
| 10亿 tokens   | \~$70.00      | 约 $26（持续运行 RTX 3060）        |

> 当月用量超过约 2 亿 tokens 时，在 Clore.ai 上自托管的成本低于 Gemini API。

## 监控 API 用量

```python
# 跟踪 Gemini API 的用量和成本
import google.generativeai as genai
import json
from datetime import datetime

genai.configure(api_key="YOUR_API_KEY")

def tracked_generate(prompt: str, log_file: str = "usage.jsonl"):
    model = genai.GenerativeModel("gemini-3.1-flash-lite")
    response = model.generate_content(prompt)
    
    # 记录用量
    usage = {
        "timestamp": datetime.utcnow().isoformat(),
        "prompt_tokens": response.usage_metadata.prompt_token_count,
        "output_tokens": response.usage_metadata.candidates_token_count,
        "total_tokens": response.usage_metadata.total_token_count,
        "estimated_cost_usd": response.usage_metadata.total_token_count / 1_000_000 * 0.07
    }
    
    with open(log_file, "a") as f:
        f.write(json.dumps(usage) + "\n")
    
    return response.text

# 用法
result = tracked_generate("法国的首都是哪里？")
print(result)
```

## 相关指南

* [Clore.ai 上的 Gemma 3](/guides/guides_v2-zh/yu-yan-mo-xing/gemma3.md) — 谷歌的开源模型家族
* [Ollama 指南](/guides/guides_v2-zh/yu-yan-mo-xing/ollama.md) — 一条命令即可在本地运行任何 LLM
* [RAGFlow](/guides/guides_v2-zh/rag-yu-xiang-liang-shu-ju-ku/ragflow.md) — 与快速模型配合良好的 RAG 流水线
* [vLLM 服务](/guides/guides_v2-zh/yu-yan-mo-xing/vllm.md) — 高吞吐、兼容 OpenAI 的服务器
* [GPU 对比](/guides/guides_v2-zh/ru-men-zhi-nan/gpu-comparison.md) — 为你的需求找到最便宜的 GPU

***

*最后更新：2026年3月16日 | Gemini 3.1 Flash Lite 发布：2026年3月3日 | 权重：仅限 API（Google）*


---

# 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.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/gemini-3-1-flash-lite.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.
