在 OpenClaw 中使用 Gemini。
Google Gemini 可通过 RunAPI 的 OpenAI 兼容端点调用 — Gemini 3.5 Flash 实现亚 100 毫秒的首字延迟,3.x Pro 应对复杂推理,2.5 Pro 服务于生产工作负载。OpenClaw 将其视为又一个 OpenAI 兼容模型,因此为 GPT 提供动力的同一套 provider 配置和 RUNAPI_API_KEY 也能调用 Gemini。无需 Google Cloud 项目,无需服务账号,无需 Vertex AI 配置。
使用 RunAPI 向 Google Gemini 3.5 Flash 发送聊天请求。
要求:
- 使用 RunAPI 的 OpenAI 兼容端点 https://runapi.ai/v1/chat/completions
- 将 model 设为 "gemini-3.5-flash"
- 使用 RUNAPI_API_KEY 环境变量进行授权
- 响应是同步的 — 回复内容位于 choices[0].message.content
- 如需流式,将 stream 设为 true 并处理 server-sent events
curl -X POST https://runapi.ai/v1/chat/completions \
-H "Authorization: Bearer $RUNAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.5-flash",
"messages": [
{"role": "system", "content": "You are a concise technical assistant."},
{"role": "user", "content": "Explain the difference between gRPC and REST in three sentences."}
],
"temperature": 0.7,
"max_tokens": 256
}'
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"model": "gemini-3.5-flash",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "gRPC uses HTTP/2 and Protocol Buffers for strongly-typed, multiplexed RPC calls with built-in code generation. REST uses HTTP/1.1 (or 2) with JSON payloads and relies on URL paths and HTTP verbs for resource semantics. gRPC is faster for service-to-service calls; REST is simpler to debug and more widely supported by browsers."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 34,
"completion_tokens": 71,
"total_tokens": 105
}
}
三步在 OpenClaw 中使用 Gemini
Configure RunAPI
Set the RUNAPI_API_KEY environment variable. If you already configured RunAPI as an OpenClaw provider, the same key and baseUrl work for Gemini — just change the model ID. No Google Cloud credentials needed.
export RUNAPI_API_KEY=runapi_xxx
Call Gemini via chat completions
Send a POST request to /v1/chat/completions with model set to gemini-3.5-flash. Pass a messages array with system and user roles. The endpoint accepts the same OpenAI-compatible shape your agent already uses for GPT models.
POST /v1/chat/completions
Read the response
The response arrives synchronously in OpenAI chat completion format. The assistant reply is in choices[0].message.content, with token usage in the usage object. For streaming, set stream to true and parse SSE events.
choices[0].message.content
Gemini chat completions API 参数
| 参数 | 类型 | 说明 |
|---|---|---|
model |
string |
Required. gemini-3.5-flash, gemini-2.5-flash, gemini-2.5-pro, gemini-3-flash-preview, gemini-3-pro-preview, or gemini-3.1-pro-preview. |
messages |
array |
Required. Array of message objects with role (system, user, assistant) and content fields. |
temperature |
number |
Optional. Sampling temperature between 0 and 2. Lower values produce more deterministic output. Default varies by model. |
max_tokens |
integer |
Optional. Maximum number of tokens to generate in the response. |
stream |
boolean |
Optional. When true, the response streams as server-sent events. Each event contains a delta with partial content. |
top_p |
number |
Optional. Nucleus sampling threshold between 0 and 1. Alternative to temperature for controlling output randomness. |
OpenClaw 上的 Gemini 是什么?
Google Gemini 通过 RunAPI 提供,无需 Google Cloud 项目、服务账号或 Vertex AI 配置。OpenClaw 将其视为另一个 OpenAI 兼容模型——相同的 provider 配置和 RUNAPI_API_KEY。Gemini 3.5 Flash 为实时 agent 循环提供亚 100ms 首 token 延迟,而 Gemini 2.5 Pro 凭借 100 万 token 上下文窗口和思考模式处理复杂推理的长上下文任务。
Gemini 使用场景
文字、图像、音频和视频的多模态应用
在文本提示旁发送图像、PDF、音频文件或视频帧,让 Gemini 进行分析、描述或提取结构化数据。Gemini 通过单次 API 调用原生处理所有输入类型。
100 万 token 上下文的长文档分析
将整个代码库、法律文档集或研究论文集输入 Gemini 2.5 Pro 的 100 万 token 上下文窗口进行分析和摘要,无需分块或检索流水线。
使用 Flash 的实时 agent 循环
将 Gemini 3.5 Flash 用于对首 token 亚 100ms 延迟比峰值推理质量更重要的速度敏感型 agent 工具调用链。每百万 token 成本处于最低水平之列。
Gemini + OpenClaw 常见问题
Yes. RunAPI provides Gemini access through its OpenAI-compatible endpoint. You only need a RUNAPI_API_KEY -- no Google Cloud project, no service account JSON, no Vertex AI billing setup.
Flash (gemini-3.5-flash) is fastest and cheapest -- best for real-time agent loops, classification, and tool-calling chains. Pro (gemini-2.5-pro) handles complex reasoning, long-context analysis, and multi-step tasks where accuracy matters more than speed.
RunAPI uses pay-per-token billing for Gemini with no free tier. However, Gemini Flash rates are among the lowest in the RunAPI catalog. Input and output tokens are metered separately. Check the RunAPI pricing page for current rates.
Yes. Both use the same RunAPI provider config and API key. Change the model parameter from gemini-3.5-flash to gpt-5.5 (or any other RunAPI model) without reconfiguring the provider. OpenClaw selects models per request.
Yes. RunAPI passes the OpenAI-compatible tools and tool_choice parameters to Gemini. Define tools in the request body and Gemini returns tool_calls in the assistant message. OpenClaw processes these the same way it handles tool calls from GPT or Claude.
立即在 OpenClaw 中试用 Gemini。
免费获取 RunAPI 密钥,在 OpenClaw provider 中将模型设为 gemini-3.5-flash,即可开始与 Gemini 对话。