Zod schemas and types for validating OpenAI /v1/models API responses, including model list and individual model structure.
// Source: https://github.com/obra/lace | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
// ABOUTME: OpenAI API response types and schemas
// ABOUTME: Defines Zod schemas for OpenAI's /v1/models endpoint responses
import { z } from 'zod';
export const OpenAIModelSchema = z.object({
id: z.string(),
object: z.literal('model'),
created: z.number(),
owned_by: z.string(),
});
export const OpenAIResponseSchema = z.object({
object: z.literal('list'),
data: z.array(OpenAIModelSchema),
});
export type OpenAIModel = z.infer<typeof OpenAIModelSchema>;
export type OpenAIResponse = z.infer<typeof OpenAIResponseSchema>;
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key