router-for-me/CLIProxyAPI · error
codex-api-key[%d].weight: %w
Error message
codex-api-key[%d].weight: %w
What it means
Returned while validating the weight field of a codex-api-key entry in config.yaml. ValidateCredentialWeight (internal/config/weight.go) rejects each cfg.CodexKey[index].Weight, and the error names the offending entry by its index. The underlying wrapped error comes from credentialweight.Normalize, which only accepts weights in (0, 1000000].
Source
Thrown at internal/config/weight.go:136
}
for index := range cfg.InteractionsKey {
if errValidate := ValidateCredentialWeight(cfg.InteractionsKey[index].Weight); errValidate != nil {
return fmt.Errorf("interactions-api-key[%d].weight: %w", index, errValidate)
}
}
for index := range cfg.ClaudeKey {
if errValidate := ValidateCredentialWeight(cfg.ClaudeKey[index].Weight); errValidate != nil {
return fmt.Errorf("claude-api-key[%d].weight: %w", index, errValidate)
}
}
for index := range cfg.VertexCompatAPIKey {
if errValidate := ValidateCredentialWeight(cfg.VertexCompatAPIKey[index].Weight); errValidate != nil {
return fmt.Errorf("vertex-api-key[%d].weight: %w", index, errValidate)
}
}
for index := range cfg.CodexKey {
if errValidate := ValidateCredentialWeight(cfg.CodexKey[index].Weight); errValidate != nil {
return fmt.Errorf("codex-api-key[%d].weight: %w", index, errValidate)
}
}
for index := range cfg.XAIKey {
if errValidate := ValidateCredentialWeight(cfg.XAIKey[index].Weight); errValidate != nil {
return fmt.Errorf("xai-api-key[%d].weight: %w", index, errValidate)
}
}
for providerIndex := range cfg.OpenAICompatibility {
for keyIndex := range cfg.OpenAICompatibility[providerIndex].APIKeyEntries {
weight := cfg.OpenAICompatibility[providerIndex].APIKeyEntries[keyIndex].Weight
if errValidate := ValidateCredentialWeight(weight); errValidate != nil {
return fmt.Errorf("openai-compatibility[%d].api-key-entries[%d].weight: %w", providerIndex, keyIndex, errValidate)
}
}
}
return nil
}
View on GitHub (pinned to 78f0c4079e)
Solutions
- Set codex-api-key[i].weight to an integer between 1 and 1000000 (or 0/negative to exclude the key from weighted routing)
- Re-run the server or trigger config reload and confirm the error is gone
- Check the other key arrays (claude-api-key, vertex-api-key, xai-api-key, openai-compatibility api-key-entries) for the same out-of-range values since they are validated in the same pass
Example fix
# before
codex-api-key:
- api-key: sk-...
weight: 5000000
# after
codex-api-key:
- api-key: sk-...
weight: 500 Defensive patterns
Strategy: validation
Validate before calling
// Go: validate config weights before starting the server
import "cliproxy/internal/credentialweight"
func checkWeights(weights []int64) error {
for i, w := range weights {
if _, err := credentialweight.Normalize(w); err != nil {
return fmt.Errorf("codex-api-key[%d].weight: %w", i, err)
}
}
return nil
} Prevention
- Add a CI lint that parses config.yaml and asserts every weight is an integer in 0..1000000
- Document in your runbook that weight is a proportional integer, not a percentage
- Use small integers (1..100) for weights; they are easier to eyeball and can never hit the cap
When it happens
Trigger: Loading/reloading a config.yaml where codex-api-key[i].weight is negative, zero (intentional exclusion is allowed and normalizes to 0, so this fires only for values Normalize rejects, i.e. > 1000000) or non-positive beyond the normalization rule — practically, any weight greater than 1000000, or a value the YAML parser coerces into an out-of-range integer.
Common situations: Copy-pasting a weight from another system that uses percentages or large multipliers (e.g. 5000000), a typo adding extra zeros, or treating weight as a 0-100 percentage scale when it is a proportional integer with a 1,000,000 cap.
Related errors
- codex.live-media-relay.max-sessions must not be negative
- codex.live-media-relay UDP port minimum and maximum must bot
- codex.live-media-relay.udp-port-min must not exceed udp-port
- xai-api-key[%d].weight: %w
- openai-compatibility[%d].api-key-entries[%d].weight: %w
AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15).
Data as JSON: /api/errors/c4dde702c544b265.
Report an issue: GitHub.