import {z} from 'zod' export type GetApiApiLogsRankingsArgs = {providers?: string | undefined, models?: string | undefined, aliases?: string | undefined, status?: string | undefined, objects?: string | undefined, selected_key_ids?: string | undefined, virtual_key_ids?: string | undefined, team_ids?: string | undefined, customer_ids?: string | undefined, user_ids?: string | undefined, business_unit_ids?: string | undefined, routing_rule_ids?: string | undefined, routing_engine_used?: string | undefined, start_time?: string | undefined, end_time?: string | undefined, period?: string | undefined, min_latency?: number | undefined, max_latency?: number | undefined, min_tokens?: number | undefined, max_tokens?: number | undefined, min_cost?: number | undefined, max_cost?: number | undefined, missing_cost_only?: boolean | undefined, stop_reasons?: string | undefined, cache_hit_types?: string | undefined, parent_request_id?: string | undefined, 'metadata_'?: string | undefined, content_search?: string | undefined}; export type GetApiApiLogsRankingsOptions = {baseUrl?: string | undefined, ManagementBearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiLogsRankingsResponse = z.object({rankings: z.array(z.object({model: z.string().optional(), provider: z.string().optional(), total_requests: z.number().int().optional(), success_count: z.number().int().optional(), success_rate: z.number().optional(), total_tokens: z.number().int().optional(), total_cost: z.number().optional(), avg_latency: z.number().optional(), trend: z.object({has_previous_period: z.boolean().optional(), requests_trend: z.number().optional(), tokens_trend: z.number().optional(), cost_trend: z.number().optional(), latency_trend: z.number().optional()}).optional()})).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get model usage rankings * * GET /api/logs/rankings */ export const getApiApiLogsRankings = async (args: GetApiApiLogsRankingsArgs, options?: GetApiApiLogsRankingsOptions) => { const {baseUrl = "http://localhost:8080", fetch: fetchFn = fetch, ManagementBearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.providers != null) query.append("providers", String(args.providers)) if (args.models != null) query.append("models", String(args.models)) if (args.aliases != null) query.append("aliases", String(args.aliases)) if (args.status != null) query.append("status", String(args.status)) if (args.objects != null) query.append("objects", String(args.objects)) if (args.selected_key_ids != null) query.append("selected_key_ids", String(args.selected_key_ids)) if (args.virtual_key_ids != null) query.append("virtual_key_ids", String(args.virtual_key_ids)) if (args.team_ids != null) query.append("team_ids", String(args.team_ids)) if (args.customer_ids != null) query.append("customer_ids", String(args.customer_ids)) if (args.user_ids != null) query.append("user_ids", String(args.user_ids)) if (args.business_unit_ids != null) query.append("business_unit_ids", String(args.business_unit_ids)) if (args.routing_rule_ids != null) query.append("routing_rule_ids", String(args.routing_rule_ids)) if (args.routing_engine_used != null) query.append("routing_engine_used", String(args.routing_engine_used)) if (args.start_time != null) query.append("start_time", String(args.start_time)) if (args.end_time != null) query.append("end_time", String(args.end_time)) if (args.period != null) query.append("period", String(args.period)) if (args.min_latency != null) query.append("min_latency", String(args.min_latency)) if (args.max_latency != null) query.append("max_latency", String(args.max_latency)) if (args.min_tokens != null) query.append("min_tokens", String(args.min_tokens)) if (args.max_tokens != null) query.append("max_tokens", String(args.max_tokens)) if (args.min_cost != null) query.append("min_cost", String(args.min_cost)) if (args.max_cost != null) query.append("max_cost", String(args.max_cost)) if (args.missing_cost_only != null) query.append("missing_cost_only", String(args.missing_cost_only)) if (args.stop_reasons != null) query.append("stop_reasons", String(args.stop_reasons)) if (args.cache_hit_types != null) query.append("cache_hit_types", String(args.cache_hit_types)) if (args.parent_request_id != null) query.append("parent_request_id", String(args.parent_request_id)) if (args['metadata_'] != null) query.append("metadata_", String(args['metadata_'])) if (args.content_search != null) query.append("content_search", String(args.content_search)) if (ManagementBearerAuth !== undefined) headers.set('authorization', `Bearer ${ManagementBearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/logs/rankings${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiLogsRankingsResponse, await res.json()) };