binary-husky/gpt_academic · error · ValueError

AZURE_CFG_ARRAY中配置的模型必须以azure开头

Error message

AZURE_CFG_ARRAY中配置的模型必须以azure开头

What it means

Raised during config parsing in toolbox.py:620 (read_single_conf_via_LLM area) when iterating AZURE_CFG_ARRAY: every model name used as a key in that dict must start with the literal prefix 'azure'. The prefix is the routing signal that tells the key-pattern manager to select an Azure-style key (see error 200), so a non-prefixed name would silently break key selection and is rejected upfront with ValueError.

Source

Thrown at toolbox.py:620

def load_chat_cookies():
    API_KEY, LLM_MODEL, AZURE_API_KEY = get_conf(
        "API_KEY", "LLM_MODEL", "AZURE_API_KEY"
    )
    AZURE_CFG_ARRAY, NUM_CUSTOM_BASIC_BTN = get_conf(
        "AZURE_CFG_ARRAY", "NUM_CUSTOM_BASIC_BTN"
    )

    # deal with azure openai key
    if is_any_api_key(AZURE_API_KEY):
        if is_any_api_key(API_KEY):
            API_KEY = API_KEY + "," + AZURE_API_KEY
        else:
            API_KEY = AZURE_API_KEY
    if len(AZURE_CFG_ARRAY) > 0:
        for azure_model_name, azure_cfg_dict in AZURE_CFG_ARRAY.items():
            if not azure_model_name.startswith("azure"):
                raise ValueError("AZURE_CFG_ARRAY中配置的模型必须以azure开头")
            AZURE_API_KEY_ = azure_cfg_dict["AZURE_API_KEY"]
            if is_any_api_key(AZURE_API_KEY_):
                if is_any_api_key(API_KEY):
                    API_KEY = API_KEY + "," + AZURE_API_KEY_
                else:
                    API_KEY = AZURE_API_KEY_

    customize_fn_overwrite_ = {}
    for k in range(NUM_CUSTOM_BASIC_BTN):
        customize_fn_overwrite_.update(
            {
                "自定义按钮"
                + str(k + 1): {
                    "Title": r"",
                    "Prefix": r"请在自定义菜单中定义提示词前缀.",
                    "Suffix": r"请在自定义菜单中定义提示词后缀",
                }
            }

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. Rename every key in AZURE_CFG_ARRAY to start with 'azure', e.g. 'azure-gpt-4-turbo'.
  2. Check case: the prefix must be lowercase 'azure'; fix 'Azure-...' spellings.
  3. After renaming, verify the same prefixed name is used in the model-selection UI/config so chat requests route to the Azure entry.
  4. Remove stale/unused entries from AZURE_CFG_ARRAY entirely if you no longer need them.

Example fix

# before (config_private.py)
AZURE_CFG_ARRAY = {
    "gpt-4-turbo": {
        "AZURE_API_KEY": "...",
        "AZURE_API_BASE": "https://xxx.openai.azure.com/",
        "AZURE_API_VERSION": "2024-xx-xx",
    }
}

# after
AZURE_CFG_ARRAY = {
    "azure-gpt-4-turbo": {
        "AZURE_API_KEY": "...",
        "AZURE_API_BASE": "https://xxx.openai.azure.com/",
        "AZURE_API_VERSION": "2024-xx-xx",
    }
}
Defensive patterns

Strategy: validation

Validate before calling

def validate_azure_cfg(azure_cfg_array: dict) -> list:
    bad = [name for name in azure_cfg_array if not str(name).startswith('azure')]
    if bad:
        raise ValueError(f'AZURE_CFG_ARRAY model names must start with "azure": {bad}')
    return bad

# run after loading config, before the app starts:
# validate_azure_cfg(AZURE_CFG_ARRAY)

Type guard

def is_valid_azure_cfg_name(name) -> bool:
    return isinstance(name, str) and name.startswith('azure')

Try / catch

try:
    # config load that parses AZURE_CFG_ARRAY
    ...
except ValueError as e:
    if 'azure' in str(e):
        print(f'config fix needed: prefix every AZURE_CFG_ARRAY key with "azure-": {e}')
    raise

Prevention

When it happens

Trigger: Defining AZURE_CFG_ARRAY = { "gpt-4-turbo": {...} } (missing 'azure' prefix) in config_private.py. Also triggered by renaming a deployment entry to match the upstream OpenAI model name, or by copying an example config that omits the prefix. The loop over AZURE_CFG_ARRAY.items() raises on the first offending key.

Common situations: Users migrating from the plain API_KEY setup to the multi-deployment AZURE_CFG_ARRAY setup and keeping the original model names. Typos like 'Azure-gpt-4' (capital A) since the check is case-sensitive startswith('azure'). Copy-pasting model names from the Azure portal deployment list, which are usually unprefixed.

Related errors


AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14). Data as JSON: /api/errors/66df814c9d6fa2a0. Report an issue: GitHub.