import {z} from 'zod' export type BudgetLimitEntry = {budget_duration: string, max_budget: number, reset_at?: (string | null) | undefined}; export type LiteLLMObjectPermissionBase = {mcp_servers?: (Array | null) | undefined, mcp_access_groups?: (Array | null) | undefined, mcp_tool_permissions?: ({[key: string]: Array} | null) | undefined, mcp_toolsets?: (Array | null) | undefined, blocked_tools?: (Array | null) | undefined, vector_stores?: (Array | null) | undefined, agents?: (Array | null) | undefined, agent_access_groups?: (Array | null) | undefined, models?: (Array | null) | undefined, search_tools?: (Array | null) | undefined, mcp_tool_search_enabled?: (boolean | null) | undefined, skills?: (Array | null) | undefined}; export type AllowedVectorStoreIndexItem = {index_name: string, index_permissions: Array<'read' | 'write'>}; export type RoutingGroup = {group_name: string, models: Array, routing_strategy: string, routing_strategy_args?: ({[key: string]: unknown} | null) | undefined, model_priorities?: ({[key: string]: number} | null) | undefined}; export type RetryPolicy = {BadRequestErrorRetries?: (number | null) | undefined, AuthenticationErrorRetries?: (number | null) | undefined, TimeoutErrorRetries?: (number | null) | undefined, RateLimitErrorRetries?: (number | null) | undefined, ContentPolicyViolationErrorRetries?: (number | null) | undefined, InternalServerErrorRetries?: (number | null) | undefined, ServiceUnavailableErrorRetries?: (number | null) | undefined, NotFoundErrorRetries?: (number | null) | undefined, DefaultRetries?: (number | null) | undefined}; export type UpdateRouterConfig = {routing_strategy_args?: ({[key: string]: unknown} | null) | undefined, routing_strategy?: (string | null) | undefined, routing_groups?: (Array | null) | undefined, retry_policy?: (RetryPolicy | null) | undefined, model_group_retry_policy?: ({[key: string]: RetryPolicy} | null) | undefined, model_group_affinity_config?: ({[key: string]: Array} | null) | undefined, allowed_fails?: (number | null) | undefined, cooldown_time?: (number | null) | undefined, num_retries?: (number | null) | undefined, timeout?: (number | null) | undefined, max_retries?: (number | null) | undefined, retry_after?: (number | null) | undefined, fallbacks?: (Array<{[key: string]: unknown}> | null) | undefined, context_window_fallbacks?: (Array<{[key: string]: unknown}> | null) | undefined, model_group_alias?: ({[key: string]: string | {[key: string]: unknown}} | null) | undefined, enable_tag_filtering?: (boolean | null) | undefined, weights?: (Record | null) | undefined, tag_routing_prefix?: (string | null) | undefined, optional_pre_call_checks?: (Array<'prompt_caching' | 'router_budget_limiting' | 'responses_api_deployment_check' | 'deployment_affinity' | 'session_affinity' | 'forward_client_headers_by_model_group' | 'enforce_model_rate_limits' | 'encrypted_content_affinity'> | null) | undefined}; export type LiteLLMKeyType = 'llm_api' | 'management' | 'read_only' | 'default'; export type GenerateKeyRequest = {key_alias?: (string | null) | undefined, duration?: (string | null) | undefined, models?: (Array | null) | undefined, spend?: (number | null) | undefined, max_budget?: (number | null) | undefined, user_id?: (string | null) | undefined, team_id?: (string | null) | undefined, agent_id?: (string | null) | undefined, max_parallel_requests?: (number | null) | undefined, metadata?: ({[key: string]: unknown} | null) | undefined, tpm_limit?: (number | null) | undefined, rpm_limit?: (number | null) | undefined, budget_duration?: (string | null) | undefined, budget_limits?: (Array | null) | undefined, allowed_cache_controls?: (Array | null) | undefined, config?: ({[key: string]: unknown} | null) | undefined, permissions?: ({[key: string]: unknown} | null) | undefined, model_max_budget?: ({[key: string]: unknown} | null) | undefined, budget_fallbacks?: ({[key: string]: Array} | null) | undefined, model_rpm_limit?: ({[key: string]: unknown} | null) | undefined, model_tpm_limit?: ({[key: string]: unknown} | null) | undefined, mcp_rpm_limit?: ({[key: string]: number} | null) | undefined, tag_rpm_limit?: ({[key: string]: number} | null) | undefined, guardrails?: (Array | null) | undefined, policies?: (Array | null) | undefined, prompts?: (Array | null) | undefined, blocked?: (boolean | null) | undefined, aliases?: ({[key: string]: unknown} | null) | undefined, object_permission?: (LiteLLMObjectPermissionBase | null) | undefined, key?: (string | null) | undefined, tpd_limit?: (number | null) | undefined, default_estimated_output_tokens?: (number | null) | undefined, default_estimated_output_tokens_per_model?: ({[key: string]: number} | null) | undefined, budget_id?: (string | null) | undefined, end_user_budget_id?: (string | null) | undefined, tags?: (Array | null) | undefined, disable_global_guardrails?: (boolean | null) | undefined, enable_prompt_caching?: (boolean | null) | undefined, throttle_on_budget_exceeded?: (boolean | null) | undefined, enforced_params?: (Array | null) | undefined, allowed_routes?: (Array | null) | undefined, allowed_passthrough_routes?: (Array | null) | undefined, denied_passthrough_routes?: (Array | null) | undefined, allowed_vector_store_indexes?: (Array | null) | undefined, rpm_limit_type?: ('guaranteed_throughput' | 'best_effort_throughput' | 'dynamic' | null) | undefined, tpm_limit_type?: ('guaranteed_throughput' | 'best_effort_throughput' | 'dynamic' | null) | undefined, router_settings?: (UpdateRouterConfig | null) | undefined, access_group_ids?: (Array | null) | undefined, soft_budget?: (number | null) | undefined, send_invite_email?: (boolean | null) | undefined, key_type?: (LiteLLMKeyType | null) | undefined, auto_rotate?: (boolean | null) | undefined, rotation_interval?: (string | null) | undefined, organization_id?: (string | null) | undefined, project_id?: (string | null) | undefined}; export type CreateApiKeyServiceAccountGenerateArgs = {'litellm-changed-by'?: (string | null) | undefined, body: GenerateKeyRequest}; export type CreateApiKeyServiceAccountGenerateOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiKeyServiceAccountGenerateResponse = z.unknown(); 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 }; /** * Generate Service Account Key Fn * * POST /key/service-account/generate */ export const createApiKeyServiceAccountGenerate = async (args: CreateApiKeyServiceAccountGenerateArgs, options: CreateApiKeyServiceAccountGenerateOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['litellm-changed-by'] != null) headers.set("litellm-changed-by", String(args['litellm-changed-by'])) if (APIKeyHeader !== undefined) headers.set("x-litellm-api-key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/key/service-account/generate${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(createApiKeyServiceAccountGenerateResponse, await res.json()) };