{"record":{"id":"7b9a800b0c6f608a","repo":"multica-ai/multica","slug":"get-runtime-usage-w","errorCode":null,"errorMessage":"get runtime usage: %w","messagePattern":"get runtime usage: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/cmd/multica/cmd_runtime.go","lineNumber":159,"sourceCode":"\nfunc runRuntimeUsage(cmd *cobra.Command, args []string) error {\n\tclient, err := newAPIClient(cmd)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tdays, _ := cmd.Flags().GetInt(\"days\")\n\tif days < 1 || days > 365 {\n\t\treturn fmt.Errorf(\"--days must be between 1 and 365\")\n\t}\n\n\tctx, cancel := cli.APIContext(context.Background())\n\tdefer cancel()\n\n\tvar usage []map[string]any\n\tpath := fmt.Sprintf(\"/api/runtimes/%s/usage?days=%d\", args[0], days)\n\tif err := client.GetJSON(ctx, path, &usage); err != nil {\n\t\treturn fmt.Errorf(\"get runtime usage: %w\", err)\n\t}\n\n\toutput, _ := cmd.Flags().GetString(\"output\")\n\tif output == \"json\" {\n\t\treturn cli.PrintJSON(os.Stdout, usage)\n\t}\n\n\theaders := []string{\"DATE\", \"PROVIDER\", \"MODEL\", \"INPUT_TOKENS\", \"OUTPUT_TOKENS\", \"CACHE_READ\", \"CACHE_WRITE\"}\n\trows := make([][]string, 0, len(usage))\n\tfor _, u := range usage {\n\t\trows = append(rows, []string{\n\t\t\tstrVal(u, \"date\"),\n\t\t\tstrVal(u, \"provider\"),\n\t\t\tstrVal(u, \"model\"),\n\t\t\tstrVal(u, \"input_tokens\"),\n\t\t\tstrVal(u, \"output_tokens\"),\n\t\t\tstrVal(u, \"cache_read_tokens\"),\n\t\t\tstrVal(u, \"cache_write_tokens\"),","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/cmd/multica/cmd_runtime.go#L141-L177","documentation":"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.","triggerScenarios":"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.","commonSituations":"Copy-pasted runtime ID from a different environment/tenant; trailing whitespace in a scripted ID; runtime deleted between `runtime list` and `runtime usage`.","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."],"exampleFix":"# before\nmultica runtime usage rt_123 --days 7   # rt_123 deleted -> 404 wrapped in \"get runtime usage\"\n\n# after\nmultica runtime list            # find current ID\nmultica runtime usage rt_9ab --days 7","handlingStrategy":"validation","validationCode":"id := strings.TrimSpace(args[0])\nif id == \"\" || strings.ContainsAny(id, \" /\") {\n\treturn fmt.Errorf(\"invalid runtime id: %q\", args[0])\n}","typeGuard":null,"tryCatchPattern":"if err := client.GetJSON(ctx, path, &usage); err != nil {\n\tvar status cli.HTTPStatusError\n\tif errors.As(err, &status) && status.Code == 404 {\n\t\t// runtime missing: refresh IDs via /api/runtimes\n\t}\n\treturn fmt.Errorf(\"get runtime usage: %w\", err)\n}","preventionTips":["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."],"tags":["go","cli","http","runtimes","usage","path-parameter"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}