multica-ai/multica · error
get runtime usage: %w
Error message
get runtime usage: %w
What it means
runRuntimeUsage wraps a failed client.GetJSON to GET /api/runtimes/{args[0]}/usage?days={days}. The runtime ID is interpolated unescaped, so besides the usual transport/auth/decode causes, a malformed ID can produce a surprising 404 or routing error. The days value is already validated (1-365) by the time this runs.
Source
Thrown at server/cmd/multica/cmd_runtime.go:159
func runRuntimeUsage(cmd *cobra.Command, args []string) error {
client, err := newAPIClient(cmd)
if err != nil {
return err
}
days, _ := cmd.Flags().GetInt("days")
if days < 1 || days > 365 {
return fmt.Errorf("--days must be between 1 and 365")
}
ctx, cancel := cli.APIContext(context.Background())
defer cancel()
var usage []map[string]any
path := fmt.Sprintf("/api/runtimes/%s/usage?days=%d", args[0], days)
if err := client.GetJSON(ctx, path, &usage); err != nil {
return fmt.Errorf("get runtime usage: %w", err)
}
output, _ := cmd.Flags().GetString("output")
if output == "json" {
return cli.PrintJSON(os.Stdout, usage)
}
headers := []string{"DATE", "PROVIDER", "MODEL", "INPUT_TOKENS", "OUTPUT_TOKENS", "CACHE_READ", "CACHE_WRITE"}
rows := make([][]string, 0, len(usage))
for _, u := range usage {
rows = append(rows, []string{
strVal(u, "date"),
strVal(u, "provider"),
strVal(u, "model"),
strVal(u, "input_tokens"),
strVal(u, "output_tokens"),
strVal(u, "cache_read_tokens"),
strVal(u, "cache_write_tokens"),View on GitHub (pinned to 2c0912b6ec)
Solutions
- Confirm the ID via `multica runtime list` and re-run with the exact value.
- Trim whitespace in scripts: multica runtime usage "$(echo $RT_ID | tr -d ' ')" --days 30.
- Check auth/base URL as with error 654 if the wrapped cause is 401/connection.
Example fix
# before multica runtime usage rt_123 --days 7 # rt_123 deleted -> 404 wrapped in "get runtime usage" # after multica runtime list # find current ID multica runtime usage rt_9ab --days 7
Defensive patterns
Strategy: validation
Validate before calling
id := strings.TrimSpace(args[0])
if id == "" || strings.ContainsAny(id, " /") {
return fmt.Errorf("invalid runtime id: %q", args[0])
} Try / catch
if err := client.GetJSON(ctx, path, &usage); err != nil {
var status cli.HTTPStatusError
if errors.As(err, &status) && status.Code == 404 {
// runtime missing: refresh IDs via /api/runtimes
}
return fmt.Errorf("get runtime usage: %w", err)
} Prevention
- Always resolve runtime IDs from a fresh `multica runtime list`.
- Trim and quote IDs in scripts to avoid path-breakage.
- Handle 404 as 'stale reference' and re-list.
When it happens
Trigger: Passing a runtime ID that does not exist (404); expired auth (401); a runtime ID containing characters that break the path (spaces, slashes) so the route does not match; server unreachable.
Common situations: Copy-pasted runtime ID from a different environment/tenant; trailing whitespace in a scripted ID; runtime deleted between `runtime list` and `runtime usage`.
Related errors
AI-assisted analysis of multica-ai/multica@2c0912b6ec (2026-08-15).
Data as JSON: /api/errors/7b9a800b0c6f608a.
Report an issue: GitHub.