{"record":{"id":"87ec1d0ab940a487","repo":"binary-husky/gpt_academic","slug":"api-key-llm-model-api-key-87ec1d","errorCode":null,"errorMessage":"您提供的api-key不满足要求，不包含任何可用于{llm_model}的api-key。您可能选择了错误的模型或请求源。","messagePattern":"您提供的api-key不满足要求，不包含任何可用于(.+?)的api-key。您可能选择了错误的模型或请求源。","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"shared_utils/key_pattern_manager.py","lineNumber":134,"sourceCode":"\n    if len(avail_key_list) == 0:\n        raise RuntimeError(f\"您提供的api-key不满足要求，不包含任何可用于{llm_model}的api-key。您可能选择了错误的模型或请求源（左上角更换模型菜单中可切换openai,azure,claude,cohere等请求源）。\")\n\n    api_key = random.choice(avail_key_list) # 随机负载均衡\n    return api_key\n\n\ndef select_api_key_for_embed_models(keys, llm_model):\n    import random\n    avail_key_list = []\n    key_list = keys.split(',')\n\n    if llm_model.startswith('text-embedding-'):\n        for k in key_list:\n            if is_openai_api_key(k): avail_key_list.append(k)\n\n    if len(avail_key_list) == 0:\n        raise RuntimeError(f\"您提供的api-key不满足要求，不包含任何可用于{llm_model}的api-key。您可能选择了错误的模型或请求源。\")\n\n    api_key = random.choice(avail_key_list) # 随机负载均衡\n    return api_key\n","sourceCodeStart":116,"sourceCodeEnd":138,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/shared_utils/key_pattern_manager.py#L116-L138","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nkeys = \"b7c9f2a1...\"  # Azure-style key, model = text-embedding-3-small\nselect_api_key_for_embed_models(keys, 'text-embedding-3-small')  # -> RuntimeError\n\n# after\nkeys = \"sk-proj-xxxxxxxxxxxxxxxx\"\nselect_api_key_for_embed_models(keys, 'text-embedding-3-small')  # ok","handlingStrategy":"validation","validationCode":"from shared_utils.key_pattern_manager import is_openai_api_key\n\ndef has_key_for_embed_model(keys: str, llm_model: str) -> bool:\n    key_list = [k.strip() for k in keys.split(',') if k.strip()]\n    return llm_model.startswith('text-embedding-') and any(is_openai_api_key(k) for k in key_list)","typeGuard":null,"tryCatchPattern":"try:\n    api_key = select_api_key_for_embed_models(keys, llm_model)\nexcept RuntimeError as e:\n    # embedding requires an OpenAI-style sk- key; surface a config hint, do not retry\n    raise ConfigError(f'no usable embedding key for {llm_model}: {e}') from e","preventionTips":["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."],"tags":["api-key","embedding","configuration","provider-mismatch"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}