You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

微调Gemini基础模型访问触发403权限错误,请求技术支持

解决Gemini微调模型访问的403权限拒绝问题

问题描述

我微调了Gemini基础模型,编写Python代码尝试访问时,始终收到错误提示:

"PermissionDenied: 403 You do not have permission to access tuned model"

我已按说明配置OAuth 2.0 Client ID,验证环节成功,但请求仍无法正常执行。以下是运行的代码:

import os
import gspread
import google.generativeai as genai
from load_creds import load_creds

creds = load_creds()

genai.configure(credentials=creds)

# Configure the API key for the Google Generative AI
genai.configure(api_key="My API key")

# Configuration for text generation 
generation_config = {
    "temperature": 0.9,
    "top_p": 0.95,
    "top_k": 64,
    "max_output_tokens": 1024,
    "response_mime_type": "text/plain",
}

# Create a GenerativeModel instance
model = genai.GenerativeModel(
    model_name="tunedModels/mytunedmodel",
    generation_config=generation_config,
)

# Start a chat session
chat_session = model.start_chat(enable_automatic_function_calling=True)

# Send a message to the chat session including the file URI
response = chat_session.send_message(f"Good morning")

# Print the response
print(response.text)

可能的解决方法

  • 移除认证方式冲突:代码中同时调用了genai.configure(credentials=creds)和genai.configure(api_key="My API key"),两种认证方式会互相干扰。访问微调模型仅需使用OAuth 2.0凭证,删除genai.configure(api_key="My API key")这一行。

  • 确认账号模型权限:登录Google AI Studio的微调模型管理页面,检查目标模型的共享设置,确保当前使用OAuth凭证的账号被添加为授权访问用户。

  • 核对模型名称准确性:确认model_name参数的格式和拼写完全正确,必须是tunedModels/[你的微调模型ID],注意大小写和特殊字符。

  • 检查OAuth权限范围:确保生成OAuth Client ID时,请求的权限范围包含https://www.googleapis.com/auth/generative-language.tuning和https://www.googleapis.com/auth/generative-language,缺少必要范围会导致访问被拒。

  • 刷新OAuth凭证:如果使用的是缓存的旧凭证,可能存在权限未更新或过期的情况,重新生成并加载最新的OAuth凭证文件。

内容的提问来源于stack exchange,提问作者Jonathan Livingston Seagull

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 08:27:34