{"record":{"id":"cfc1ba6143299700","repo":"JuliusBrussee/caveman","slug":"cache-replay-openai-api-key-unavailable","errorCode":null,"errorMessage":"cache-replay: OPENAI_API_KEY unavailable","messagePattern":"cache-replay: OPENAI_API_KEY unavailable","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cacheengine/cmd/cache-replay/main.go","lineNumber":377,"sourceCode":"\tif err != nil {\n\t\treturn nil, \"\", err\n\t}\n\tif limited.N <= 0 {\n\t\treturn nil, \"\", fmt.Errorf(\"cache-replay: trace exceeds %d bytes\", maxBytes)\n\t}\n\treturn records, hex.EncodeToString(hash.Sum(nil)), nil\n}\n\nfunc validateProviderCredentials(records []cachebench.TraceRecord) error {\n\tproviders := map[string]bool{}\n\tfor _, record := range records {\n\t\tproviders[record.Provider] = true\n\t}\n\tfor provider := range providers {\n\t\tswitch provider {\n\t\tcase \"openai\":\n\t\t\tif os.Getenv(\"OPENAI_API_KEY\") == \"\" {\n\t\t\t\treturn errors.New(\"cache-replay: OPENAI_API_KEY unavailable\")\n\t\t\t}\n\t\tcase \"anthropic\":\n\t\t\tif os.Getenv(\"ANTHROPIC_API_KEY\") == \"\" {\n\t\t\t\treturn errors.New(\"cache-replay: ANTHROPIC_API_KEY unavailable\")\n\t\t\t}\n\t\tcase \"gemini\":\n\t\t\tif os.Getenv(\"GEMINI_API_KEY\") == \"\" {\n\t\t\t\treturn errors.New(\"cache-replay: GEMINI_API_KEY unavailable\")\n\t\t\t}\n\t\tcase \"bedrock\":\n\t\t\tif os.Getenv(\"AWS_BEARER_TOKEN_BEDROCK\") == \"\" && (os.Getenv(\"AWS_ACCESS_KEY_ID\") == \"\" || os.Getenv(\"AWS_SECRET_ACCESS_KEY\") == \"\") {\n\t\t\t\treturn errors.New(\"cache-replay: Bedrock bearer token or AWS access credentials unavailable\")\n\t\t\t}\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"cache-replay: unsupported provider %q\", provider)\n\t\t}\n\t}\n\treturn nil","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/cacheengine/cmd/cache-replay/main.go#L359-L395","documentation":"validateProviderCredentials found trace records for the 'openai' provider but the OPENAI_API_KEY environment variable is unset/empty. The command checks only presence (not validity) before replay so failures surface before any spend.","triggerScenarios":"Thrown at cacheengine/cmd/cache-replay/main.go:377 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Export OPENAI_API_KEY in the environment running cache-replay","Store the key in a sourced env file or secret manager that populates the variable"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"766dce6b1394ebb56a3090748d5a0240a5aefb36","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}