import {z} from 'zod' export type ProjectDefaultServiceTier = 'standard' | 'fast' | 'scale'; export type ProjectOptionalServiceTier = 'flex' | 'fast' | 'ultrafast'; export type UpdateProjectServiceTierSettingsBody = {default: ProjectDefaultServiceTier, enabled_tiers?: ('all' | Array) | undefined} | {default?: ProjectDefaultServiceTier | undefined, enabled_tiers: 'all' | Array}; export type CreateApiOrganizationProjectsProjectIdServiceTierSettingsArgs = {project_id: string, body: UpdateProjectServiceTierSettingsBody}; export type CreateApiOrganizationProjectsProjectIdServiceTierSettingsOptions = {baseUrl?: string | undefined, AdminApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const projectDefaultServiceTier = z.enum(["standard", "fast", "scale"]); export const projectOptionalServiceTier = z.enum(["flex", "fast", "ultrafast"]); export const projectServiceTierSettingsResource = z.object({object: z.literal("project.service_tier_settings"), default: projectDefaultServiceTier, enabled_tiers: z.union([z.literal("all"), z.array(projectOptionalServiceTier)])}); 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 }; /** * Update project service tier settings * * POST /organization/projects/{project_id}/service_tier_settings */ export const createApiOrganizationProjectsProjectIdServiceTierSettings = async (args: CreateApiOrganizationProjectsProjectIdServiceTierSettingsArgs, options?: CreateApiOrganizationProjectsProjectIdServiceTierSettingsOptions) => { const {baseUrl = "https://api.openai.com/v1", fetch: fetchFn = fetch, AdminApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (AdminApiKeyAuth !== undefined) headers.set('authorization', `Bearer ${AdminApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/organization/projects/${encodeURIComponent(String(args.project_id))}/service_tier_settings${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(projectServiceTierSettingsResource, await res.json()) };