{"record":{"id":"c4dde702c544b265","repo":"router-for-me/CLIProxyAPI","slug":"codex-api-key-d-weight-w","errorCode":null,"errorMessage":"codex-api-key[%d].weight: %w","messagePattern":"codex-api-key\\[(.+?)\\]\\.weight: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/weight.go","lineNumber":136,"sourceCode":"\t}\n\tfor index := range cfg.InteractionsKey {\n\t\tif errValidate := ValidateCredentialWeight(cfg.InteractionsKey[index].Weight); errValidate != nil {\n\t\t\treturn fmt.Errorf(\"interactions-api-key[%d].weight: %w\", index, errValidate)\n\t\t}\n\t}\n\tfor index := range cfg.ClaudeKey {\n\t\tif errValidate := ValidateCredentialWeight(cfg.ClaudeKey[index].Weight); errValidate != nil {\n\t\t\treturn fmt.Errorf(\"claude-api-key[%d].weight: %w\", index, errValidate)\n\t\t}\n\t}\n\tfor index := range cfg.VertexCompatAPIKey {\n\t\tif errValidate := ValidateCredentialWeight(cfg.VertexCompatAPIKey[index].Weight); errValidate != nil {\n\t\t\treturn fmt.Errorf(\"vertex-api-key[%d].weight: %w\", index, errValidate)\n\t\t}\n\t}\n\tfor index := range cfg.CodexKey {\n\t\tif errValidate := ValidateCredentialWeight(cfg.CodexKey[index].Weight); errValidate != nil {\n\t\t\treturn fmt.Errorf(\"codex-api-key[%d].weight: %w\", index, errValidate)\n\t\t}\n\t}\n\tfor index := range cfg.XAIKey {\n\t\tif errValidate := ValidateCredentialWeight(cfg.XAIKey[index].Weight); errValidate != nil {\n\t\t\treturn fmt.Errorf(\"xai-api-key[%d].weight: %w\", index, errValidate)\n\t\t}\n\t}\n\tfor providerIndex := range cfg.OpenAICompatibility {\n\t\tfor keyIndex := range cfg.OpenAICompatibility[providerIndex].APIKeyEntries {\n\t\t\tweight := cfg.OpenAICompatibility[providerIndex].APIKeyEntries[keyIndex].Weight\n\t\t\tif errValidate := ValidateCredentialWeight(weight); errValidate != nil {\n\t\t\t\treturn fmt.Errorf(\"openai-compatibility[%d].api-key-entries[%d].weight: %w\", providerIndex, keyIndex, errValidate)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/config/weight.go#L118-L154","documentation":"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].","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\ncodex-api-key:\n  - api-key: sk-...\n    weight: 5000000\n\n# after\ncodex-api-key:\n  - api-key: sk-...\n    weight: 500","handlingStrategy":"validation","validationCode":"// Go: validate config weights before starting the server\nimport \"cliproxy/internal/credentialweight\"\n\nfunc checkWeights(weights []int64) error {\n    for i, w := range weights {\n        if _, err := credentialweight.Normalize(w); err != nil {\n            return fmt.Errorf(\"codex-api-key[%d].weight: %w\", i, err)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["config","validation","load-balancing","codex"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}