Skip to content

ccusage / data-loader / usageDataSchema

Variable: usageDataSchema

ts
const usageDataSchema: ObjectSchema<{
  cwd: OptionalSchema<StringSchema<undefined>, undefined>;
  sessionId: OptionalSchema<SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Session ID cannot be empty">, BrandAction<string, "SessionId">]>, undefined>;
  timestamp: SchemaWithPipe<readonly [StringSchema<undefined>, RegexAction<string, "Invalid ISO timestamp">, BrandAction<string, "ISOTimestamp">]>;
  version: OptionalSchema<SchemaWithPipe<readonly [StringSchema<undefined>, RegexAction<string, "Invalid version format">, BrandAction<string, "Version">]>, undefined>;
  message: ObjectSchema<{
     usage: ObjectSchema<{
        input_tokens: NumberSchema<undefined>;
        output_tokens: NumberSchema<undefined>;
        cache_creation_input_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
        cache_read_input_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
     }, undefined>;
     model: OptionalSchema<SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Model name cannot be empty">, BrandAction<string, "ModelName">]>, undefined>;
     id: OptionalSchema<SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Message ID cannot be empty">, BrandAction<string, "MessageId">]>, undefined>;
     content: OptionalSchema<ArraySchema<ObjectSchema<{
        text: OptionalSchema<StringSchema<undefined>, undefined>;
     }, undefined>, undefined>, undefined>;
  }, undefined>;
  costUSD: OptionalSchema<NumberSchema<undefined>, undefined>;
  requestId: OptionalSchema<SchemaWithPipe<readonly [StringSchema<undefined>, MinLengthAction<string, 1, "Request ID cannot be empty">, BrandAction<string, "RequestId">]>, undefined>;
  isApiErrorMessage: OptionalSchema<BooleanSchema<undefined>, undefined>;
}, undefined>;

Valibot schema for validating Claude usage data from JSONL files

Released under the MIT License.