From c12e92c807f8ed6486119024ba859d689708a689 Mon Sep 17 00:00:00 2001 From: Theodore Li Date: Fri, 13 Feb 2026 10:18:37 -0800 Subject: [PATCH] Consolidate byok type definitions --- .../settings-modal/components/byok/byok.tsx | 2 +- apps/sim/hooks/queries/byok-keys.ts | 3 +-- apps/sim/lib/api-key/byok.ts | 3 +-- apps/sim/tools/index.ts | 17 ++--------------- apps/sim/tools/types.ts | 18 ++++-------------- 5 files changed, 9 insertions(+), 34 deletions(-) diff --git a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/byok/byok.tsx b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/byok/byok.tsx index 0ded2e324..39f308d9e 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/byok/byok.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/byok/byok.tsx @@ -17,11 +17,11 @@ import { AnthropicIcon, ExaAIIcon, GeminiIcon, MistralIcon, OpenAIIcon } from '@ import { Skeleton } from '@/components/ui' import { type BYOKKey, - type BYOKProviderId, useBYOKKeys, useDeleteBYOKKey, useUpsertBYOKKey, } from '@/hooks/queries/byok-keys' +import type { BYOKProviderId } from '@/tools/types' const logger = createLogger('BYOKSettings') diff --git a/apps/sim/hooks/queries/byok-keys.ts b/apps/sim/hooks/queries/byok-keys.ts index e62379e54..167238f4a 100644 --- a/apps/sim/hooks/queries/byok-keys.ts +++ b/apps/sim/hooks/queries/byok-keys.ts @@ -1,11 +1,10 @@ import { createLogger } from '@sim/logger' import { keepPreviousData, useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { API_ENDPOINTS } from '@/stores/constants' +import type { BYOKProviderId } from '@/tools/types' const logger = createLogger('BYOKKeysQueries') -export type BYOKProviderId = 'openai' | 'anthropic' | 'google' | 'mistral' | 'exa' - export interface BYOKKey { id: string providerId: BYOKProviderId diff --git a/apps/sim/lib/api-key/byok.ts b/apps/sim/lib/api-key/byok.ts index 90bc439c7..127feb9af 100644 --- a/apps/sim/lib/api-key/byok.ts +++ b/apps/sim/lib/api-key/byok.ts @@ -7,11 +7,10 @@ import { isHosted } from '@/lib/core/config/feature-flags' import { decryptSecret } from '@/lib/core/security/encryption' import { getHostedModels } from '@/providers/models' import { useProvidersStore } from '@/stores/providers/store' +import type { BYOKProviderId } from '@/tools/types' const logger = createLogger('BYOKKeys') -export type BYOKProviderId = 'openai' | 'anthropic' | 'google' | 'mistral' | 'exa' - export interface BYOKKeyResult { apiKey: string isBYOK: true diff --git a/apps/sim/tools/index.ts b/apps/sim/tools/index.ts index 1c0ead1db..841fa1439 100644 --- a/apps/sim/tools/index.ts +++ b/apps/sim/tools/index.ts @@ -18,6 +18,7 @@ import type { ExecutionContext } from '@/executor/types' import type { ErrorInfo } from '@/tools/error-extractors' import { extractErrorMessage } from '@/tools/error-extractors' import type { + BYOKProviderId, OAuthTokenPayload, ToolConfig, ToolHostingPricing, @@ -79,19 +80,13 @@ async function injectHostedKeyIfNeeded( if (!isHosted) return { isUsingHostedKey: false } const { envKeys, apiKeyParam, byokProviderId } = tool.hosting - const userProvidedKey = params[apiKeyParam] - - if (userProvidedKey) { - logger.debug(`[${requestId}] User provided API key for ${tool.id}, skipping hosted key`) - return { isUsingHostedKey: false } - } // Check BYOK workspace key first if (byokProviderId && executionContext?.workspaceId) { try { const byokResult = await getBYOKKey( executionContext.workspaceId, - byokProviderId as 'openai' | 'anthropic' | 'google' | 'mistral' | 'exa' + byokProviderId as BYOKProviderId ) if (byokResult) { params[apiKeyParam] = byokResult.apiKey @@ -199,14 +194,6 @@ function calculateToolCost( case 'per_request': return { cost: pricing.cost } - case 'per_second': { - const duration = pricing.getDuration(response) - const billableDuration = pricing.minimumSeconds - ? Math.max(duration, pricing.minimumSeconds) - : duration - return { cost: billableDuration * pricing.costPerSecond } - } - case 'custom': { const result = pricing.getCost(params, response) if (typeof result === 'number') { diff --git a/apps/sim/tools/types.ts b/apps/sim/tools/types.ts index 2ba7a2a97..bf4b5c09b 100644 --- a/apps/sim/tools/types.ts +++ b/apps/sim/tools/types.ts @@ -1,5 +1,7 @@ import type { OAuthService } from '@/lib/oauth' +export type BYOKProviderId = 'openai' | 'anthropic' | 'google' | 'mistral' | 'exa' + export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' export type OutputType = @@ -188,17 +190,6 @@ export interface PerRequestPricing { cost: number } -/** Billed by execution duration (e.g., browser sessions, video processing) */ -export interface PerSecondPricing { - type: 'per_second' - /** Cost per second in dollars */ - costPerSecond: number - /** Minimum billable seconds */ - minimumSeconds?: number - /** Extract duration from response (in seconds) */ - getDuration: (response: Record) => number -} - /** Result from custom pricing calculation */ export interface CustomPricingResult { /** Cost in dollars */ @@ -217,7 +208,6 @@ export interface CustomPricing

, R extends ToolRespon /** Union of all pricing models */ export type ToolHostingPricing

, R extends ToolResponse = ToolResponse> = | PerRequestPricing - | PerSecondPricing | CustomPricing /** @@ -229,8 +219,8 @@ export interface ToolHostingConfig

, R extends ToolRe envKeys: string[] /** The parameter name that receives the API key */ apiKeyParam: string - /** BYOK provider ID for workspace key lookup (e.g., 'serper') */ - byokProviderId?: string + /** BYOK provider ID for workspace key lookup */ + byokProviderId?: BYOKProviderId /** Pricing when using hosted key */ pricing: ToolHostingPricing }