import {z} from 'zod' export type AiGatewayProviderUpdateAttributes = {cost_multiplier?: number | undefined, name?: string | undefined}; export type AiGatewayProviderType = 'providers'; export type AiGatewayProviderUpdateData = {attributes: AiGatewayProviderUpdateAttributes, id: string, type: AiGatewayProviderType}; export type AiGatewayProviderUpdateRequest = {data: AiGatewayProviderUpdateData}; export type PatchApiApiV2ProvidersIdArgs = {id: number, body: AiGatewayProviderUpdateRequest}; export type PatchApiApiV2ProvidersIdOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, appKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const aiGatewayCustomProviderSupportedOperation = z.enum(["OPENAI_CHAT_COMPLETIONS", "OPENAI_RESPONSES", "ANTHROPIC_MESSAGES"]); export const aiGatewayProviderIntegrationConfig = z.object({bedrock_region: z.string().max(64).optional(), foundry_project: z.string().max(256).optional(), foundry_resource_id: z.string().max(512).optional(), location: z.string().max(256).optional(), project_id: z.string().max(256).optional(), supported_operations: z.array(aiGatewayCustomProviderSupportedOperation).optional()}); export const aiGatewayKnownProvider = z.enum(["custom", "anthropic", "openai", "azure_openai", "bedrock", "gemini", "baseten", "fireworks", "together", "typesafe", "azure_foundry"]); export const aiGatewayProviderAttributes = z.object({cost_multiplier: z.number(), created_at: z.string(), integration_account_id: z.string(), integration_config: aiGatewayProviderIntegrationConfig.optional(), known_provider: aiGatewayKnownProvider, name: z.string(), slug: z.string(), updated_at: z.string()}); export const aiGatewayModelCatalogEntryType = z.literal("model-catalog-entries"); export const aiGatewayModelCatalogEntryIdentifier = z.object({id: z.string(), type: aiGatewayModelCatalogEntryType}); export const aiGatewayProviderModelsRelationshipData = z.array(aiGatewayModelCatalogEntryIdentifier); export const aiGatewayProviderModelsRelationship = z.object({data: aiGatewayProviderModelsRelationshipData}); export const aiGatewayProviderRelationships = z.object({models: aiGatewayProviderModelsRelationship}); export const aiGatewayProviderType = z.literal("providers"); export const aiGatewayProviderResource = z.object({attributes: aiGatewayProviderAttributes, id: z.string(), relationships: aiGatewayProviderRelationships.optional(), type: aiGatewayProviderType}); export const aiGatewayModelCapabilities = z.object({attachment: z.boolean().optional(), interleaved_reasoning: z.boolean().optional(), reasoning: z.boolean().optional(), structured_output: z.boolean().optional(), temperature: z.boolean().optional(), tool_call: z.boolean().optional()}); export const aiGatewayModelMetadataKind = z.enum(["language", "embedding", "image", "audio", "decision", "reranking"]); export const aiGatewayModelMetadataLifecycle = z.enum(["active", "alpha", "beta", "deprecated"]); export const aiGatewayModelLimits = z.object({context_window_tokens: z.number().int().gte(0).optional(), max_input_tokens: z.number().int().gte(0).optional(), max_output_tokens: z.number().int().gte(0).optional()}); export const aiGatewayModelModalities = z.object({input: z.array(z.string()).optional(), output: z.array(z.string()).optional()}); export const aiGatewayModelReasoningControlType = z.enum(["toggle", "effort", "budget_tokens"]); export const aiGatewayModelReasoningControl = z.object({effort_levels: z.array(z.string().nullable()).optional(), max_budget_tokens: z.number().int().gte(0).optional(), min_budget_tokens: z.number().int().gte(-1).optional(), type: aiGatewayModelReasoningControlType}); export const aiGatewayModelReasoning = z.object({controls: z.array(aiGatewayModelReasoningControl)}); export const aiGatewayModelReferencePrice = z.object({amount: z.string(), component: z.string(), context_max_tokens: z.number().int().gte(1).optional(), context_min_tokens: z.number().int().gte(0), currency: z.string(), mode: z.string(), service_tier: z.string().optional(), unit: z.string()}); export const aiGatewayModelMetadataSourceMatchedBy = z.enum(["override", "wire_id", "canonical_id", "wire_id_date_suffix", "canonical_model"]); export const aiGatewayModelMetadataSource = z.object({matched_by: aiGatewayModelMetadataSourceMatchedBy, model_id: z.string(), name: z.string(), observed_at: z.string().optional(), provider: z.string(), revision: z.string().optional()}); export const aiGatewayModelMetadataStatus = z.enum(["available", "partial"]); export const aiGatewayModelMetadata = z.object({capabilities: aiGatewayModelCapabilities, description: z.string().optional(), display_name: z.string().optional(), family: z.string().optional(), kind: aiGatewayModelMetadataKind.optional(), knowledge_cutoff: z.string().optional(), last_updated: z.string().optional(), lifecycle: aiGatewayModelMetadataLifecycle.optional(), limits: aiGatewayModelLimits, modalities: aiGatewayModelModalities, open_weights: z.boolean().optional(), reasoning: aiGatewayModelReasoning.optional(), reference_pricing: z.array(aiGatewayModelReferencePrice).optional(), release_date: z.string().optional(), source: aiGatewayModelMetadataSource, status: aiGatewayModelMetadataStatus}); export const aiGatewayModelSource = z.enum(["discovered", "manual"]); export const aiGatewaySupportedOperation = z.enum(["ANTHROPIC_MESSAGES", "ANTHROPIC_COUNT_TOKENS", "OPENAI_CHAT_COMPLETIONS", "OPENAI_RESPONSES", "OPENAI_WEB_SEARCH", "OPENAI_EMBEDDINGS", "GEMINI_GENERATE_CONTENT", "GEMINI_RAW_PREDICTIONS"]); export const aiGatewayModelCatalogEntryAttributes = z.object({created_at: z.string(), enabled: z.boolean(), metadata: aiGatewayModelMetadata.optional(), model_id_canonical: z.string(), model_id_wire: z.string(), provider_id: z.number().int(), source: aiGatewayModelSource, supported_operations: z.array(aiGatewaySupportedOperation), updated_at: z.string()}); export const aiGatewayModelCatalogEntryResource = z.object({attributes: aiGatewayModelCatalogEntryAttributes, id: z.string(), type: aiGatewayModelCatalogEntryType}); export const aiGatewayProviderResponse = z.object({data: aiGatewayProviderResource, included: z.array(aiGatewayModelCatalogEntryResource).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 }; /** * Update an AI Gateway provider * * PATCH /api/v2/providers/{id} * * Also accepts auth: AuthZ */ export const patchApiApiV2ProvidersId = async (args: PatchApiApiV2ProvidersIdArgs, options?: PatchApiApiV2ProvidersIdOptions) => { const {baseUrl = "https://api.datadoghq.com", fetch: fetchFn = fetch, apiKeyAuth, appKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("DD-API-KEY", apiKeyAuth) if (appKeyAuth !== undefined) headers.set("DD-APPLICATION-KEY", appKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/providers/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(aiGatewayProviderResponse, await res.json()) };