import {z} from 'zod' export type GetApiV1AiGatewaysGatewayIdModelProvidersArgs = {'page[size]'?: number | undefined, 'page[after]'?: string | undefined}; export type GetApiV1AiGatewaysGatewayIdModelProvidersOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const uUID = z.string(); export const createdAt = z.string(); export const updatedAt = z.string(); export const aIGatewayEntityIdentifier = z.string().min(1).max(256); export const publicLabels = z.record(z.string(), z.string().min(1).max(63)); export const managedBy = z.record(z.string(), z.string().min(1).max(63)); export const aIGatewayDatastoreName = z.string().min(2).max(255); export const aIGatewayDatastoreRef = z.object({name: aIGatewayDatastoreName}); export const aIGatewayTokenVaultDatastores = z.array(aIGatewayDatastoreRef); export const aIGatewayTokenVaultCredentialPlacement = z.object({location: z.enum(["header", "body", "query"]).optional(), name: z.string().optional(), prefix: z.string().optional()}); export const aIGatewayTokenVaultCredential = z.object({inbound: aIGatewayTokenVaultCredentialPlacement.optional(), outbound: aIGatewayTokenVaultCredentialPlacement.optional()}); export const aIGatewayRedisAWSAuthentication = z.object({type: z.literal("aws"), access_key_id: z.string().optional(), assume_role_arn: z.string().optional(), cache_name: z.string().optional(), is_serverless: z.boolean().optional(), region: z.string().optional(), role_session_name: z.string().optional(), secret_access_key: z.string().optional()}); export const aIGatewayRedisAzureAuthentication = z.object({type: z.literal("azure"), client_id: z.string().optional(), client_secret: z.string().optional(), tenant_id: z.string().optional()}); export const aIGatewayRedisGCPAuthentication = z.object({type: z.literal("gcp"), service_account_json: z.string().optional()}); export const aIGatewayRedisCloudConfiguration = z.object({cloud_authentication: z.discriminatedUnion("type", [aIGatewayRedisAWSAuthentication, aIGatewayRedisAzureAuthentication, aIGatewayRedisGCPAuthentication]).optional(), cluster: z.object({max_redirections: z.number().int().gte(0).lte(2147483646).optional(), nodes: z.array(z.object({ip: z.string().optional(), port: z.number().int().gte(0).lte(65535).optional()})).optional()}).optional(), connect_timeout: z.number().int().gte(0).lte(2147483646).optional(), connection_is_proxied: z.boolean().optional(), database: z.number().int().gte(0).lte(2147483646).optional(), host: z.string().optional(), keepalive: z.object({backlog: z.number().int().gte(0).lte(2147483646).optional(), pool_size: z.number().int().gte(1).lte(2147483646).optional()}).optional(), password: z.string().optional(), port: z.union([z.number().int().gte(0).lte(65535), z.string()]).optional(), read_timeout: z.number().int().gte(0).lte(2147483646).optional(), send_timeout: z.number().int().gte(0).lte(2147483646).optional(), sentinel: z.object({master: z.string().optional(), nodes: z.array(z.object({host: z.string().optional(), port: z.number().int().gte(0).lte(65535).optional()})).optional(), password: z.string().optional(), role: z.enum(["any", "master", "slave"]).optional(), username: z.string().optional()}).optional(), server_name: z.string().optional(), ssl: z.boolean().optional(), ssl_verify: z.boolean().optional(), username: z.string().optional()}); export const tokenVaultDatastoreKey = z.object({version: z.string(), key: z.string().optional()}); export const tokenVaultDatastoreConfig = z.object({directory: z.string(), current_version: z.string(), keys: z.array(tokenVaultDatastoreKey)}); export const aIGatewayTokenVault = z.object({provider: z.string(), subject_token_type: z.enum(["access_token", "api_key"]).optional(), credential: aIGatewayTokenVaultCredential.optional(), cache: z.object({redis: aIGatewayRedisCloudConfiguration.optional()}).optional(), storage: tokenVaultDatastoreConfig.optional()}); export const aIGatewayModelProviderConfigAuthBasic = z.object({type: z.literal("basic"), headers: z.array(z.object({name: z.string(), value: z.string().optional()})).optional(), params: z.array(z.object({name: z.string(), value: z.string().optional(), location: z.enum(["body", "query"])})).optional()}); export const aIGatewayModelProviderConfigAuthAzure = z.object({type: z.literal("azure"), client_id: z.string().optional(), client_secret: z.string().optional(), tenant_id: z.string().optional(), use_managed_identity: z.boolean().optional()}); export const aIGatewayModelProviderConfigAuthAWS = z.object({type: z.literal("aws"), access_key_id: z.string().optional(), secret_access_key: z.string().optional(), session_token: z.string().optional(), assume_role_arn: z.string().optional(), role_session_name: z.string().optional(), sts_endpoint_url: z.string().optional(), batch_role_arn: z.string().optional()}); export const aIGatewayUpstreamAuthAWS = z.object({type: z.literal("aws"), access_key_id: z.string().optional(), secret_access_key: z.string().optional(), session_token: z.string().optional(), region: z.string().optional(), assume_role_arn: z.string().optional(), role_session_name: z.string().optional(), sts_endpoint_url: z.string().optional()}); export const authGCPWorkloadIdentityFederation = z.object({source: z.literal("aws_iam"), auth_json: z.string().optional(), aws: aIGatewayUpstreamAuthAWS.optional()}); export const aIGatewayModelProviderConfigAuthGCP = z.object({type: z.literal("gcp"), service_account_json: z.string().optional(), metadata_url: z.string().optional(), oauth_token_url: z.string().optional(), use_gcp_service_account: z.boolean().optional(), workload_identity_federation: authGCPWorkloadIdentityFederation.optional()}); export const aIGatewayModelProviderConfigAuthSagemaker = z.object({type: z.literal("sagemaker"), aws: z.object({access_key_id: z.string().optional(), secret_access_key: z.string().optional(), session_token: z.string().optional()}).optional()}); export const aIGatewayModelProvider = z.discriminatedUnion("type", [z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("anthropic"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: aIGatewayModelProviderConfigAuthBasic})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("azure"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: z.discriminatedUnion("type", [aIGatewayModelProviderConfigAuthBasic, aIGatewayModelProviderConfigAuthAzure]), service: z.enum(["azure-openai", "azure-foundry"]).optional(), instance: z.string().optional(), foundry: z.object({resource: z.string(), domain: z.string().optional()}).optional()})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("baseten"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: aIGatewayModelProviderConfigAuthBasic})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("bedrock"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: z.discriminatedUnion("type", [aIGatewayModelProviderConfigAuthBasic, aIGatewayModelProviderConfigAuthAWS])})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("cerebras"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: aIGatewayModelProviderConfigAuthBasic})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("cohere"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: aIGatewayModelProviderConfigAuthBasic})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("dashscope"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: aIGatewayModelProviderConfigAuthBasic})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("databricks"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: aIGatewayModelProviderConfigAuthBasic})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("deepseek"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: aIGatewayModelProviderConfigAuthBasic})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("gemini"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: z.discriminatedUnion("type", [aIGatewayModelProviderConfigAuthBasic, aIGatewayModelProviderConfigAuthGCP])})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("huggingface"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: aIGatewayModelProviderConfigAuthBasic})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("kimi"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: aIGatewayModelProviderConfigAuthBasic})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("llama2"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: aIGatewayModelProviderConfigAuthBasic})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("mistral"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: aIGatewayModelProviderConfigAuthBasic})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("ollama"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: aIGatewayModelProviderConfigAuthBasic})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("openai"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: aIGatewayModelProviderConfigAuthBasic})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("vercel"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: aIGatewayModelProviderConfigAuthBasic})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("vllm"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: aIGatewayModelProviderConfigAuthBasic})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("xai"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: aIGatewayModelProviderConfigAuthBasic})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("sagemaker"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: z.discriminatedUnion("type", [aIGatewayModelProviderConfigAuthBasic, aIGatewayModelProviderConfigAuthSagemaker])})}), z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, type: z.literal("typesafe"), display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), datastores: aIGatewayTokenVaultDatastores.optional(), token_vault: aIGatewayTokenVault.optional(), config: z.object({auth: aIGatewayModelProviderConfigAuthBasic})})]); export const cursorMetaPage = z.object({first: z.string().optional(), last: z.string().optional(), next: z.string().nullable(), previous: z.string().nullable(), size: z.number()}); export const cursorMeta = z.object({page: cursorMetaPage}); export const getApiV1AiGatewaysGatewayIdModelProvidersResponse = z.object({data: z.array(aIGatewayModelProvider), meta: cursorMeta}); 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 }; /** * List AI Gateway Model Providers * * GET /v1/ai-gateways/{gatewayId}/model-providers * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const getApiV1AiGatewaysGatewayIdModelProviders = async (args: GetApiV1AiGatewaysGatewayIdModelProvidersArgs, options?: GetApiV1AiGatewaysGatewayIdModelProvidersOptions) => { const {baseUrl = "https://global.api.konghq.com", fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args['page[after]'] != null) query.append("page[after]", String(args['page[after]'])) if (personalAccessToken !== undefined) headers.set('authorization', `Bearer ${personalAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/ai-gateways/${encodeURIComponent(String(args.gatewayId))}/model-providers${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(getApiV1AiGatewaysGatewayIdModelProvidersResponse, await res.json()) };