router-for-me/CLIProxyAPI · error

home models payload has no sections

Error message

home models payload has no sections

What it means

The home models payload parsed as valid JSON of the expected map shape, but the map contains no sections (len(bySection) == 0, i.e. '{}'). Each top-level key is expected to be a section holding an array of model objects; an empty object means the structure is present but empty.

Source

Thrown at internal/api/server_routes.go:978

	}
	var top map[string]json.RawMessage
	if errUnmarshal := json.Unmarshal(raw, &top); errUnmarshal != nil {
		return nil, false
	}
	return top, true
}

func decodeHomeModels(raw []byte) ([]homeModelEntry, error) {
	if len(raw) == 0 {
		return nil, fmt.Errorf("home models payload is empty")
	}

	var bySection map[string][]map[string]any
	if err := json.Unmarshal(raw, &bySection); err != nil {
		return nil, fmt.Errorf("parse home models payload: %w", err)
	}
	if len(bySection) == 0 {
		return nil, fmt.Errorf("home models payload has no sections")
	}

	seen := make(map[string]struct{})
	out := make([]homeModelEntry, 0, 256)
	for _, models := range bySection {
		for _, model := range models {
			id, _ := model["id"].(string)
			id = strings.TrimSpace(id)
			if id == "" {
				name, _ := model["name"].(string)
				name = strings.TrimSpace(name)
				id = strings.TrimPrefix(name, "models/")
			}
			if id == "" {
				continue
			}
			if _, ok := seen[id]; ok {
				continue

View on GitHub (pinned to 78f0c4079e)

Solutions

  1. Fetch the payload manually (curl with the same auth) and inspect the top-level keys
  2. If the account genuinely has no models, surface a clearer message about an empty catalog rather than a parse error
  3. If a local file is the source, restore or repopulate it
Defensive patterns

Strategy: validation

Validate before calling

sections, ok := topLevelObjectKeys(raw)
if ok && len(sections) == 0 {
	// empty catalog: skip decode instead of erroring
}

Prevention

When it happens

Trigger: Upstream returned literal '{}' for the models payload; a filtering layer removed all sections before decode; a config-driven home models file was created empty.

Common situations: Region-restricted accounts getting an empty catalog; an upstream A/B change; a user-edited local models file reduced to '{}'.

Related errors


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