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

如何在启用API密钥的Oobabooga中通过Python获取模型列表

解决Oobabooga启用API密钥后获取模型列表的授权问题

当你在CMD_FLAGS.txt中启用--api-key配置后,Oobabooga的所有API接口都会强制要求携带密钥认证,这就是调用/internal/model/list时返回{'detail': 'Unauthorized'}的原因。

下面提供两种可行的解决方法,都能让你在保持API密钥启用的状态下成功获取模型列表:

方法一:在请求头中添加Authorization字段

直接在请求头里带上Bearer格式的API密钥,修改后的代码如下:

import requests

url = "http://127.0.0.1:5000/v1"
api_key = "enter-your-fake-api-key-here"  # 替换成你实际设置的密钥

headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {api_key}"
}

response = requests.get(f'{url}/internal/model/list',
                        headers=headers,
                        verify=False)
print(response.json())

方法二:通过URL查询参数传递API密钥

把API密钥直接拼在请求URL的末尾作为query参数,代码示例:

import requests

url = "http://127.0.0.1:5000/v1"
api_key = "enter-your-fake-api-key-here"  # 替换成你实际设置的密钥

headers = {
    "Content-Type": "application/json"
}

response = requests.get(f'{url}/internal/model/list?api-key={api_key}',
                        headers=headers,
                        verify=False)
print(response.json())

两种方法任选其一即可,执行后就能正常返回预期的模型列表,同时不会影响你使用openai.client进行后续的模型交互。

内容的提问来源于stack exchange,提问作者unknown name

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 12:52:44