{"record":{"id":"86ed5a3f7a9ec0b3","repo":"BoundaryML/baml","slug":"failed-to-get-input-tokens-w","errorCode":null,"errorMessage":"failed to get input tokens: %w","messagePattern":"failed to get input tokens: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_usage.go","lineNumber":30,"sourceCode":"\t*raw_objects.RawObject\n}\n\nfunc newUsage(ptr int64, rt unsafe.Pointer) Usage {\n\treturn &usage{raw_objects.FromPointer(ptr, rt)}\n}\n\nfunc (u *usage) ObjectType() cffi.BamlObjectType {\n\treturn cffi.BamlObjectType_OBJECT_USAGE\n}\n\nfunc (u *usage) pointer() int64 {\n\treturn u.RawObject.Pointer()\n}\n\nfunc (u *usage) InputTokens() (int64, error) {\n\tresult, err := raw_objects.CallMethod(u, \"input_tokens\", nil)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to get input tokens: %w\", err)\n\t}\n\n\ttokens, ok := result.(int64)\n\tif !ok {\n\t\treturn 0, fmt.Errorf(\"unexpected type for input tokens: %T\", result)\n\t}\n\n\treturn tokens, nil\n}\n\nfunc (u *usage) OutputTokens() (int64, error) {\n\tresult, err := raw_objects.CallMethod(u, \"output_tokens\", nil)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to get output tokens: %w\", err)\n\t}\n\n\ttokens, ok := result.(int64)\n\tif !ok {","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_usage.go#L12-L48","documentation":"The Go raw-objects usage wrapper calls the underlying 'input_tokens' method on the internal usage object. If that method call fails, the error is wrapped with 'failed to get input tokens: %w'. This indicates the collector's internal object is missing or in an unexpected state.","triggerScenarios":"Calling collector/LlmCall Usage().InputTokens() before the LLM call produced usage data, or when the underlying PyO3 raw object does not expose input_tokens.","commonSituations":"Reading usage from a failed or still-streaming call; mixing collector APIs with raw object wrappers; version drift between the Go client and the embedded runtime.","solutions":["Check the LLM call completed successfully before reading usage","Verify the collector call/stream finished (await stream.Done()) before Usage()","Update baml Go client and runtime to matching versions","Inspect the wrapped error via errors.Unwrap for the root cause"],"exampleFix":"// before\ntokens, _ := call.Usage().InputTokens()\n// after\nresp, err := ctx.LlmCall(...)\nif err != nil { return err }\ntokens, err := resp.Usage().InputTokens()\nif err != nil { return err }","handlingStrategy":"try-catch","validationCode":"if call == nil || call.Usage() == nil {\n    return fmt.Errorf(\"no usage available\")\n}","typeGuard":null,"tryCatchPattern":"tokens, err := usage.InputTokens()\nif err != nil {\n    return fmt.Errorf(\"usage read failed: %w\", err)\n}","preventionTips":["Only read Usage() after the call/stream completes","Check the LLM call error before usage","Keep the Go client and BAML runtime versions aligned","Log errors.Unwrap(err) to see the root cause"],"tags":["go","usage","collector","raw-objects"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}