WayToClawEarn
Beginner30 min readMay 20, 2026

How to build an automated coding assistant with Gemini 3.5 Flash API: a complete 30-minute tutorial

From registering the API to building a multi-step coding workflow, a complete tutorial that can be used even if you have no basic knowledge.

Beginner · 30 min · May 20, 2026

Tutorial Objectives

In 30 minutes, use Gemini 3.5 Flash API to build an automated coding assistant to achieve a three-in-one workflow of code generation, review and refactoring. This article is a complete step-by-step tutorial.

What will you build?

  • Coding Assistant Core: Code generation and review system based on Gemini 3.5 Flash
  • Automated pipeline: end-to-end workflow from requirement description to code output
  • Quality Monitoring: Automatic code review and refactoring suggestions

Preparation list

  • Google AI Studio or Gemini API account (free quota available) -Basic Python and terminal operation knowledge
  • An API key (get it in 5 minutes)

Overall architecture

The teaching process is broken down into 4 modules and can be advanced in order. When it's all done, you'll have an AI coding assistant that you can actually use.

ModuleInputOutputEstimated time
Get API KeyGoogle AccountGemini API Key5 minutes
Environment setupTerminalPython SDK ready5 minutes
Core Coding AssistantAPI KeysCode Generation Functions12 min
Automated WorkflowsCoding FunctionsComplete Pipeline8 Minutes

Text example picture — Gemini 3.5 Flash agentic coding setup

Step 1: Get Gemini 3.5 Flash API Key

Gemini 3.5 Flash was just announced today via Google I/O 2026 and is available directly through Google AI Studio. Visit Google AI Studio and log in with your Google account:

  1. Click "Get API Key" in the upper right corner
  2. Create or select a project in the Google Cloud Console
  3. Enable Gemini API and generate API key
  4. Copy the key and save it to a safe location
terminal

# 保存密钥为环境变量
export GEMINI_API_KEY="你的_API_密钥"

提示:Gemini 3.5 Flash 定价为 $1.50/百万输入 token 和 $9.00/百万输出 token,比 2.5 Flash 贵了约 3 倍,但性能接近旗舰模型。对于个人开发者来说,免费额度足够日常使用。

第 2 步:安装 Python SDK 并验证连通性

Gemini 官方提供了 google-genai Python SDK,安装非常简单:

terminal

# 安装 Gemini Python SDK
pip install google-genai

# 验证安装
python3 -c "import google.genai; print('SDK ready')"

接下来验证 API 连通性:

python
from google import genai

client = genai.Client(api_key="你的_API_密钥")
response = client.models.generate_content(
    model="gemini-3.5-flash",
    contents="用 Python 写一个快速排序函数"
)
print(response.text[:200])

如果看到生成的代码输出,说明 API 正常工作。

配置项说明
模型名gemini-3.5-flash稳定版,非 preview
输入定价$1.50/M tokens百万 token 计算
输出定价$9.00/M tokens含思维链 token
上下文窗口1,000,000 tokens适合长文件处理

第 3 步:搭建编码助手核心功能

有了 SDK 基础,我们来搭建一个多功能编码助手。这个函数可以处理代码生成、审查和重构三大任务:

python
from google import genai
import os

client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])

def coding_assistant(task_type, input_text):
    """多功能编码助手:generate / review / refactor"""
    prompts = {
        "generate": f"请根据以下需求生成完整可运行的代码,包含必要注释:

{input_text}",
        "review": f"请审查以下代码,指出问题、安全漏洞和优化建议:

{input_text} __T OK13__ {input_text}

"
    }

    response = client.models.generate_content(
        model="gemini-3.5-flash",
        contents=prompts.get(task_type, input_text),
        config={
            "temperature": 0.3,  # 编码任务降低随机性
            "max_output_tokens": 4096
        }
    )
    return response.text

# 测试:生成一个简单的 Web 服务器
result = coding_assistant("generate", "用 Python Flask 写一个 REST API,包含用户 CRUD 操作")
print(result[:500])

提示:Gemini 3.5 Flash 在编码任务上表现非常出色——Google 官方将其定位为「最强的 agentic 和 coding 模型」。它的思维链能力让代码输出质量接近 Anthropic Claude。

第 4 步:搭建自动化多步骤编码工作流

这是最关键的一步——将编码助手封装为自动化管道,实现从需求到最终代码输出的完整流程:

python
import json
from google import genai

client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])

class CodingPipeline:
    def __init__(self):
        self.history = []

    def generate_code(self, requirement):
        step1 = client.models.generate_content(
            model="gemini-3.5-flash",
            contents=f"作为资深工程师,请分析以下需求并输出技术设计方案:

{requirement}"
        )
        design = step1.text
        self.history.append({"step": "design", "output": design[:200]})

        step2 = client.models.generate_content(
            model="gemini-3.5-flash",
            contents=f"基于以下设计方案,生成完整可运行的代码:

{design}"
        )
        code = step2.text
        self.history.append({"step": "code", "output": code[:200]})

        step3 = client.models.generate_content(
            model="gemini-3.5-flash",
            contents=f"审查以下代码并输出优化建议:

{code}"
        )
        review = step3.text
        self.history.append({"step": "review", "output": review[:200]})

        return {"design": design, "code": code, "review": review}

# 使用管道
pipeline = CodingPipeline()
result = pipeline.generate_code("一个命令行 Todo 应用,支持添加、删除、标记完成")
print(json.dumps(result, indent=2))

进阶:接入 n8n 自动化

将这个编码管道接入 n8n,可以让 AI 编码助手自动响应 GitHub Issue、Slack 消息或定时任务。推荐使用 n8n Cloud 托管节点,省去自建服务器的麻烦。

有人实践成功 AI 自动化工作流后实现了可观收入:一位自由开发者通过 Claude Code + n8n 搭建 AI 自动化系统,6 个月从 $4,000 做到 $12,000/月。另一位数据分析师也通过类似方案达到 月入 $3,800

常见问题排查(FAQ)

Q1:API 返回 429 Too Many Requests?

Gemini API 有免费额度限制,建议使用 time.sleep() 控制请求间隔,或升级到付费套餐。

Q2:代码输出不完整?

检查 max_output_tokens 设置,Gemini 3.5 Flash 默认输出较短,建议设为 4096 或更高。

Q3:Gemini 3.5 Flash 和 Claude Code 怎么选?

Gemini 3.5 Flash 胜在速度(推理更快)和性价比($9/M 输出 vs Claude 的 $15/M)。如果你是预算敏感的独立开发者,推荐通过 OpenRouter 统一管理多个模型,按需切换。

SEO+GEO:FAQ 结构满足 GEO 提取偏好,同时覆盖长尾搜索词

工具词条(触发工具悬浮卡)

正文中自然出现的工具名,平台侧会匹配已维护 tools 库生成 hover-card:GeminiGemini APIGoogle AI StudioPythonn8nClaude CodeOpenRouterGoogle Cloud

Reference video/material

Internal link guidance

Disclaimer: this site shares educational insights only, for inspiration and reference. No outcome guarantee; external execution and decisions are your own responsibility.

Related tutorials