Skip to content

Commit c12e92c

Browse files
author
Theodore Li
committed
Consolidate byok type definitions
1 parent d174a6a commit c12e92c

File tree

5 files changed

+9
-34
lines changed

5 files changed

+9
-34
lines changed

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/byok/byok.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import { AnthropicIcon, ExaAIIcon, GeminiIcon, MistralIcon, OpenAIIcon } from '@
1717
import { Skeleton } from '@/components/ui'
1818
import {
1919
type BYOKKey,
20-
type BYOKProviderId,
2120
useBYOKKeys,
2221
useDeleteBYOKKey,
2322
useUpsertBYOKKey,
2423
} from '@/hooks/queries/byok-keys'
24+
import type { BYOKProviderId } from '@/tools/types'
2525

2626
const logger = createLogger('BYOKSettings')
2727

apps/sim/hooks/queries/byok-keys.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { createLogger } from '@sim/logger'
22
import { keepPreviousData, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
33
import { API_ENDPOINTS } from '@/stores/constants'
4+
import type { BYOKProviderId } from '@/tools/types'
45

56
const logger = createLogger('BYOKKeysQueries')
67

7-
export type BYOKProviderId = 'openai' | 'anthropic' | 'google' | 'mistral' | 'exa'
8-
98
export interface BYOKKey {
109
id: string
1110
providerId: BYOKProviderId

apps/sim/lib/api-key/byok.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import { isHosted } from '@/lib/core/config/feature-flags'
77
import { decryptSecret } from '@/lib/core/security/encryption'
88
import { getHostedModels } from '@/providers/models'
99
import { useProvidersStore } from '@/stores/providers/store'
10+
import type { BYOKProviderId } from '@/tools/types'
1011

1112
const logger = createLogger('BYOKKeys')
1213

13-
export type BYOKProviderId = 'openai' | 'anthropic' | 'google' | 'mistral' | 'exa'
14-
1514
export interface BYOKKeyResult {
1615
apiKey: string
1716
isBYOK: true

apps/sim/tools/index.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type { ExecutionContext } from '@/executor/types'
1818
import type { ErrorInfo } from '@/tools/error-extractors'
1919
import { extractErrorMessage } from '@/tools/error-extractors'
2020
import type {
21+
BYOKProviderId,
2122
OAuthTokenPayload,
2223
ToolConfig,
2324
ToolHostingPricing,
@@ -79,19 +80,13 @@ async function injectHostedKeyIfNeeded(
7980
if (!isHosted) return { isUsingHostedKey: false }
8081

8182
const { envKeys, apiKeyParam, byokProviderId } = tool.hosting
82-
const userProvidedKey = params[apiKeyParam]
83-
84-
if (userProvidedKey) {
85-
logger.debug(`[${requestId}] User provided API key for ${tool.id}, skipping hosted key`)
86-
return { isUsingHostedKey: false }
87-
}
8883

8984
// Check BYOK workspace key first
9085
if (byokProviderId && executionContext?.workspaceId) {
9186
try {
9287
const byokResult = await getBYOKKey(
9388
executionContext.workspaceId,
94-
byokProviderId as 'openai' | 'anthropic' | 'google' | 'mistral' | 'exa'
89+
byokProviderId as BYOKProviderId
9590
)
9691
if (byokResult) {
9792
params[apiKeyParam] = byokResult.apiKey
@@ -199,14 +194,6 @@ function calculateToolCost(
199194
case 'per_request':
200195
return { cost: pricing.cost }
201196

202-
case 'per_second': {
203-
const duration = pricing.getDuration(response)
204-
const billableDuration = pricing.minimumSeconds
205-
? Math.max(duration, pricing.minimumSeconds)
206-
: duration
207-
return { cost: billableDuration * pricing.costPerSecond }
208-
}
209-
210197
case 'custom': {
211198
const result = pricing.getCost(params, response)
212199
if (typeof result === 'number') {

apps/sim/tools/types.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { OAuthService } from '@/lib/oauth'
22

3+
export type BYOKProviderId = 'openai' | 'anthropic' | 'google' | 'mistral' | 'exa'
4+
35
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD'
46

57
export type OutputType =
@@ -188,17 +190,6 @@ export interface PerRequestPricing {
188190
cost: number
189191
}
190192

191-
/** Billed by execution duration (e.g., browser sessions, video processing) */
192-
export interface PerSecondPricing {
193-
type: 'per_second'
194-
/** Cost per second in dollars */
195-
costPerSecond: number
196-
/** Minimum billable seconds */
197-
minimumSeconds?: number
198-
/** Extract duration from response (in seconds) */
199-
getDuration: (response: Record<string, unknown>) => number
200-
}
201-
202193
/** Result from custom pricing calculation */
203194
export interface CustomPricingResult {
204195
/** Cost in dollars */
@@ -217,7 +208,6 @@ export interface CustomPricing<P = Record<string, unknown>, R extends ToolRespon
217208
/** Union of all pricing models */
218209
export type ToolHostingPricing<P = Record<string, unknown>, R extends ToolResponse = ToolResponse> =
219210
| PerRequestPricing
220-
| PerSecondPricing
221211
| CustomPricing<P, R>
222212

223213
/**
@@ -229,8 +219,8 @@ export interface ToolHostingConfig<P = Record<string, unknown>, R extends ToolRe
229219
envKeys: string[]
230220
/** The parameter name that receives the API key */
231221
apiKeyParam: string
232-
/** BYOK provider ID for workspace key lookup (e.g., 'serper') */
233-
byokProviderId?: string
222+
/** BYOK provider ID for workspace key lookup */
223+
byokProviderId?: BYOKProviderId
234224
/** Pricing when using hosted key */
235225
pricing: ToolHostingPricing<P, R>
236226
}

0 commit comments

Comments
 (0)