binary-husky/gpt_academic · error · RuntimeError
您提供的api-key不满足要求,不包含任何可用于{llm_model}的api-key。您可能选择了错误的模型或请求源
Error message
您提供的api-key不满足要求,不包含任何可用于{llm_model}的api-key。您可能选择了错误的模型或请求源。 What it means
Raised by select_api_key_for_embed_models in shared_utils/key_pattern_manager.py:134 when the key pool contains no key matching the OpenAI key pattern for a text-embedding-* model. The only branch handled is llm_model.startswith('text-embedding-'), which accepts keys passing is_openai_api_key; every other situation (wrong provider key, or no key at all) leaves avail_key_list empty and triggers this RuntimeError. It is the embedding-pipeline counterpart of error 200.
Source
Thrown at shared_utils/key_pattern_manager.py:134
if len(avail_key_list) == 0:
raise RuntimeError(f"您提供的api-key不满足要求,不包含任何可用于{llm_model}的api-key。您可能选择了错误的模型或请求源(左上角更换模型菜单中可切换openai,azure,claude,cohere等请求源)。")
api_key = random.choice(avail_key_list) # 随机负载均衡
return api_key
def select_api_key_for_embed_models(keys, llm_model):
import random
avail_key_list = []
key_list = keys.split(',')
if llm_model.startswith('text-embedding-'):
for k in key_list:
if is_openai_api_key(k): avail_key_list.append(k)
if len(avail_key_list) == 0:
raise RuntimeError(f"您提供的api-key不满足要求,不包含任何可用于{llm_model}的api-key。您可能选择了错误的模型或请求源。")
api_key = random.choice(avail_key_list) # 随机负载均衡
return api_key
View on GitHub (pinned to d6bde0fa54)
Solutions
- Add a valid OpenAI-format key (sk-...) to the key pool used for embeddings in config_private.py (e.g. API_KEY or the embedding-specific key setting).
- Verify the embedding model name is 'text-embedding-*' and matches the provider of the configured key.
- Strip whitespace/quotes and remove empty entries from the comma-separated key string.
- If you only have Azure OpenAI, use an Azure embedding deployment through a custom key-pattern registration or switch to a provider whose key pattern is supported for embeddings.
Example fix
# before keys = "b7c9f2a1..." # Azure-style key, model = text-embedding-3-small select_api_key_for_embed_models(keys, 'text-embedding-3-small') # -> RuntimeError # after keys = "sk-proj-xxxxxxxxxxxxxxxx" select_api_key_for_embed_models(keys, 'text-embedding-3-small') # ok
Defensive patterns
Strategy: validation
Validate before calling
from shared_utils.key_pattern_manager import is_openai_api_key
def has_key_for_embed_model(keys: str, llm_model: str) -> bool:
key_list = [k.strip() for k in keys.split(',') if k.strip()]
return llm_model.startswith('text-embedding-') and any(is_openai_api_key(k) for k in key_list) Try / catch
try:
api_key = select_api_key_for_embed_models(keys, llm_model)
except RuntimeError as e:
# embedding requires an OpenAI-style sk- key; surface a config hint, do not retry
raise ConfigError(f'no usable embedding key for {llm_model}: {e}') from e Prevention
- Always keep at least one OpenAI-format key (sk-...) configured when using text-embedding-* models, even if chat uses another provider.
- Validate embedding keys at startup alongside chat keys.
- Clean the comma-separated key list (strip spaces, remove empties) before passing it in.
When it happens
Trigger: Calling select_api_key_for_embed_models(keys, llm_model) with llm_model like 'text-embedding-3-large' while keys contains only Azure/cohere/other-provider keys or empty strings. Also fires when the model name is not a text-embedding-* name but the caller still routes here with a non-OpenAI key, since no other prefix branch exists to populate avail_key_list.
Common situations: Using the knowledge-base / vector-search plugins (which embed documents) with only an Azure OpenAI key configured, because AZURE models were routed for chat but embeddings still expect an sk- OpenAI key. Empty EMBEDDING key configuration. Keys with whitespace or pasted with surrounding quotes that fail is_openai_api_key.
Related errors
- 您提供的api-key不满足要求,不包含任何可用于{llm_model}的api-key。您可能选择了错误的模型或请求源
- 你提供了错误的API_KEY。 1. 临时解决方案:直接在输入区键入api_key,然后回车提交。 2. 长效解决方
- 你提供了错误的API_KEY。 1. 临时解决方案:直接在输入区键入api_key,然后回车提交。 2. 长效解决方
- 没有设置ANTHROPIC_API_KEY选项
- 请配置 GEMINI_API_KEY。
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/87ec1d0ab940a487.
Report an issue: GitHub.