alibaba/open-code-review · error
invalid custom provider key %q: expected custom_providers.<n
Error message
invalid custom provider key %q: expected custom_providers.<name>.<field>
What it means
setCustomProviderValue expects keys of the form custom_providers.<name>.<field>. A key that does not split into exactly three non-empty segments is rejected with this message, distinguishing it from the preset-provider (providers.*) key format.
Source
Thrown at cmd/opencodereview/config_cmd.go:811
}
if _, isPreset := llm.LookupProvider(parts[1]); !isPreset {
return setCustomProviderField(cfg, parts[1], parts[2], key, value)
}
if cfg.Providers == nil {
cfg.Providers = make(map[string]ProviderEntry)
}
entry := cfg.Providers[parts[1]]
if err := applyProviderField(parts[1], &entry, parts[2], key, value); err != nil {
return err
}
cfg.Providers[parts[1]] = entry
return nil
}
func setCustomProviderValue(cfg *Config, key, value string) error {
parts := strings.SplitN(key, ".", 3)
if len(parts) != 3 || parts[1] == "" || parts[2] == "" {
return fmt.Errorf("invalid custom provider key %q: expected custom_providers.<name>.<field>", key)
}
if preset, isPreset := llm.LookupProvider(parts[1]); isPreset {
return fmt.Errorf("custom provider name %q conflicts with a preset provider; use providers.%s.%s to configure the preset or choose a different custom provider name", parts[1], preset.Name, parts[2])
}
return setCustomProviderField(cfg, parts[1], parts[2], key, value)
}
func isAuxiliaryProviderField(field string) bool {
switch field {
case "extra_body", "extra_headers", "retry_codes":
return true
default:
return false
}
}
func setCustomProviderField(cfg *Config, name, field, key, value string) error {
if _, exists := cfg.CustomProviders[name]; isAuxiliaryProviderField(field) && !exists {View on GitHub (pinned to 5cf97d0d15)
Solutions
- Use the full key: ocr config set custom_providers.<name>.<field> <value>
- If the target is a preset provider, switch to providers.<name>.<field>
- Ensure the name and field segments are non-empty
Example fix
// before ocr config set custom_providers.myprovider // after ocr config set custom_providers.myprovider.api_key sk-...
Defensive patterns
Strategy: validation
Validate before calling
key="custom_providers.myprovider.api_key"
count=$(awk -F. '{print NF}' <<< "$key")
[[ "$count" -eq 3 ]] || echo "key must be custom_providers.<name>.<field>" Try / catch
parts := strings.SplitN(key, ".", 3)
if len(parts) != 3 || parts[1] == "" || parts[2] == "" {
return fmt.Errorf("invalid custom provider key %q: expected custom_providers.<name>.<field>", key)
} Prevention
- Verify the full custom_providers.<name>.<field> shape before running
- Do not mix providers.* and custom_providers.* key styles
- Confirm environment variables feeding the key are set
When it happens
Trigger: `ocr config set custom_providers <value>` or `ocr config set custom_providers.myprovider` (missing field), or keys like custom_providers..api_key with an empty name segment.
Common situations: Using providers.* syntax for a custom provider or vice versa; scripts building keys from variables where the field variable is empty; copy-paste truncating the key.
Related errors
- invalid provider key %q: expected providers.<name>.<field>
- load config: %w
- unset supports provider, max_tokens, effort, custom_provider
- MCP server %q not found
- custom provider %q not found
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/f28314194269cfcf.
Report an issue: GitHub.