{"record":{"id":"b2a054dd525fad19","repo":"router-for-me/CLIProxyAPI","slug":"xai-api-key-d-weight-w","errorCode":null,"errorMessage":"xai-api-key[%d].weight: %w","messagePattern":"xai-api-key\\[(.+?)\\]\\.weight: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/weight.go","lineNumber":141,"sourceCode":"\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":123,"sourceCodeEnd":154,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/config/weight.go#L123-L154","documentation":"Returned while validating the weight field of an xai-api-key entry in config.yaml. The loop over cfg.XAIKey calls ValidateCredentialWeight on each entry's Weight; on failure the error identifies the entry index and wraps the underlying credentialweight.Normalize error (weight out of the allowed 1..1000000 range).","triggerScenarios":"A config.yaml (or hot-reloaded config) where xai-api-key[i].weight exceeds 1000000 or otherwise fails Normalize; validation runs before the server accepts the config, so startup or reload aborts.","commonSituations":"Migrating from a percentage-based weight scheme, adding many zeros by typo, or hand-editing the YAML after copying a template entry with a large weight.","solutions":["Set xai-api-key[i].weight to a value in 1..1000000 (use 0 or negative only if you intend to exclude the credential)","If you intended relative proportions, use small integers like 1, 3, 10","Validate the whole file with the server's config check / dry-run before reloading"],"exampleFix":"# before\nxai-api-key:\n  - api-key: xai-...\n    weight: 99999999\n\n# after\nxai-api-key:\n  - api-key: xai-...\n    weight: 10","handlingStrategy":"validation","validationCode":"func checkXAIWeights(keys []XAIKeyConfig) error {\n    for i, k := range keys {\n        if k.Weight > 1_000_000 {\n            return fmt.Errorf(\"xai-api-key[%d].weight %d exceeds 1000000\", i, k.Weight)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate weights in the same pipeline that generates config.yaml, not just at server startup","Fail CI on config errors instead of discovering them at deploy time","Keep weight scales consistent across all provider blocks"],"tags":["config","validation","load-balancing","xai"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}