import {z} from 'zod' export type GetApiV1alpha1InferenceGatewaysIdArgs = {id: string}; export type GetApiV1alpha1InferenceGatewaysIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const coreWeaveAuth = z.object({}); export const weightsAndBiasesAuth = z.object({apiKey: z.string().optional(), serverUrl: z.string().optional(), enableUsageReports: z.boolean().optional(), enableRateLimiting: z.boolean().optional()}); export const endpointConfiguration = z.object({additionalDns: z.array(z.string()).optional()}); export const bodyBasedRouting = z.object({apiType: z.literal("API_TYPE_OPENAI")}); export const headerBasedRouting = z.object({headerName: z.string()}); export const pathBasedRouting = z.object({}); export const gatewaySpec = z.object({id: z.string().optional(), name: z.string().optional(), zones: z.array(z.string()).optional(), coreWeaveAuth: coreWeaveAuth.optional(), weightsAndBiasesAuth: weightsAndBiasesAuth.optional(), organizationId: z.string().optional(), endpointConfiguration: endpointConfiguration.optional(), bodyBasedRouting: bodyBasedRouting.optional(), headerBasedRouting: headerBasedRouting.optional(), pathBasedRouting: pathBasedRouting.optional()}); export const condition = z.object({type: z.string().optional(), lastUpdateTime: z.string().optional(), reason: z.string().optional(), message: z.string().optional(), zone: z.string().optional(), status: z.enum(["True", "False", "Unknown"]).optional()}); export const gatewayStatus = z.object({createdAt: z.string().optional(), updatedAt: z.string().optional(), conditions: z.array(condition).optional(), endpoints: z.array(z.string()).optional(), status: z.enum(["STATUS_CREATING", "STATUS_READY", "STATUS_UPDATING", "STATUS_DELETING", "STATUS_ERROR"]).optional()}); export const gateway = z.object({spec: gatewaySpec.optional(), status: gatewayStatus.optional()}); export const getGatewayResponse = z.object({gateway: gateway.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 gateway * * GET /v1alpha1/inference/gateways/{id} */ export const getApiV1alpha1InferenceGatewaysId = async (args: GetApiV1alpha1InferenceGatewaysIdArgs, options?: GetApiV1alpha1InferenceGatewaysIdOptions) => { const {baseUrl = "https://api.coreweave.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1alpha1/inference/gateways/${encodeURIComponent(String(args.id))}${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(getGatewayResponse, await res.json()) };