router-for-me/CLIProxyAPI · error

openai-compatibility[%d].api-key-entries[%d].weight: %w

Error message

openai-compatibility[%d].api-key-entries[%d].weight: %w

What it means

Returned while validating weights inside an openai-compatibility provider block. Each provider's api-key-entries[keyIndex].weight is checked with ValidateCredentialWeight; the error names both the provider index and the key-entry index so you can locate the exact nested entry in config.yaml.

Source

Thrown at internal/config/weight.go:148

		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

  1. Locate openai-compatibility[p] (count from 0) and its api-key-entries[k]; set weight to 1..1000000
  2. Remember the index in the message is the array position, not a name — count entries in file order
  3. Re-check after reload; validation covers all providers so fix every flagged entry

Example fix

# before
openai-compatibility:
  - name: my-provider
    api-key-entries:
      - api-key: sk-...
        weight: 2000000

# after
openai-compatibility:
  - name: my-provider
    api-key-entries:
      - api-key: sk-...
        weight: 2
Defensive patterns

Strategy: validation

Validate before calling

for p, prov := range cfg.OpenAICompatibility {
    for k, entry := range prov.APIKeyEntries {
        if _, err := credentialweight.Normalize(entry.Weight); err != nil {
            return fmt.Errorf("openai-compatibility[%d].api-key-entries[%d].weight: %w", p, k, err)
        }
    }
}

Prevention

When it happens

Trigger: config.yaml where openai-compatibility[p].api-key-entries[k].weight fails credentialweight.Normalize (value > 1000000 or otherwise invalid). Fires at config load or hot-reload.

Common situations: Nested providers make the path easy to get wrong: editing provider-level options instead of the per-key weight, or pasting a key entry whose weight was tuned for a different system with a different scale.

Related errors


AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15). Data as JSON: /api/errors/e676d1f4c1d2118e. Report an issue: GitHub.