import {z} from 'zod' export type GetApiV1OrganizationsExternalKeysExternalKeyIdBetaTrueArgs = {external_key_id: string, 'anthropic-version'?: string | undefined}; export type GetApiV1OrganizationsExternalKeysExternalKeyIdBetaTrueOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const betaAttachedAttachment = z.object({type: z.literal("attached")}); export const betaUnattachedAttachment = z.object({type: z.literal("unattached")}); export const betaAwsExternalKeyConfig = z.object({kms_arn: z.string().max(2048), region: z.string().nullable().optional(), role_arn: z.string().nullable().optional(), type: z.literal("aws")}); export const betaGcpExternalKeyConfig = z.object({key_name: z.string(), type: z.literal("gcp")}); export const betaAzureExternalKeyConfig = z.object({client_id: z.string().nullable().optional(), key_name: z.string(), tenant_id: z.string(), type: z.literal("azure"), vault_uri: z.string()}); export const betaExternalKey = z.object({attachment: z.discriminatedUnion("type", [betaAttachedAttachment, betaUnattachedAttachment]), created_at: z.string(), display_name: z.string().nullable(), geo: z.string(), id: z.string(), provider_config: z.discriminatedUnion("type", [betaAwsExternalKeyConfig, betaGcpExternalKeyConfig, betaAzureExternalKeyConfig]), type: z.literal("external_key"), updated_at: z.string(), user_profile_id: z.string().nullable()}); 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 External Key * * GET /v1/organizations/external_keys/{external_key_id}?beta=true */ export const getApiV1OrganizationsExternalKeysExternalKeyIdBetaTrue = async (args: GetApiV1OrganizationsExternalKeysExternalKeyIdBetaTrueArgs, options?: GetApiV1OrganizationsExternalKeysExternalKeyIdBetaTrueOptions) => { const {baseUrl = "https://api.anthropic.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['anthropic-version'] != null) headers.set("anthropic-version", String(args['anthropic-version'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/organizations/external_keys/${encodeURIComponent(String(args.external_key_id))}?beta=true${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(betaExternalKey, await res.json()) };