/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod"; import { remap as remap$ } from "../lib/primitives.js"; import { safeParse } from "../lib/schemas.js"; import { Result as SafeParseResult } from "../types/fp.js"; import { SDKValidationError } from "./sdkvalidationerror.js"; /** * Usage statistics. * * @remarks * * For streaming responses, `usage` field is included in the very last response chunk returned. * * Note that returning `usage` for streaming requests is an OpenAI API extension. If you use OpenAI SDK, you might access the field directly even if it's not present in the type signature in the SDK. */ export type UsageInfo = { /** * The number of tokens in the prompt. */ promptTokens: number; /** * The number of tokens in the generated completion. */ completionTokens?: number | undefined; /** * The total number of tokens used in the request (prompt + completion). */ totalTokens: number; }; /** @internal */ export const UsageInfo$inboundSchema: z.ZodType< UsageInfo, z.ZodTypeDef, unknown > = z.object({ prompt_tokens: z.number().int(), completion_tokens: z.number().int().optional(), total_tokens: z.number().int(), }).transform((v) => { return remap$(v, { "prompt_tokens": "promptTokens", "completion_tokens": "completionTokens", "total_tokens": "totalTokens", }); }); /** @internal */ export type UsageInfo$Outbound = { prompt_tokens: number; completion_tokens?: number | undefined; total_tokens: number; }; /** @internal */ export const UsageInfo$outboundSchema: z.ZodType< UsageInfo$Outbound, z.ZodTypeDef, UsageInfo > = z.object({ promptTokens: z.number().int(), completionTokens: z.number().int().optional(), totalTokens: z.number().int(), }).transform((v) => { return remap$(v, { promptTokens: "prompt_tokens", completionTokens: "completion_tokens", totalTokens: "total_tokens", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace UsageInfo$ { /** @deprecated use `UsageInfo$inboundSchema` instead. */ export const inboundSchema = UsageInfo$inboundSchema; /** @deprecated use `UsageInfo$outboundSchema` instead. */ export const outboundSchema = UsageInfo$outboundSchema; /** @deprecated use `UsageInfo$Outbound` instead. */ export type Outbound = UsageInfo$Outbound; } export function usageInfoToJSON(usageInfo: UsageInfo): string { return JSON.stringify(UsageInfo$outboundSchema.parse(usageInfo)); } export function usageInfoFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => UsageInfo$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'UsageInfo' from JSON`, ); }