Consolidate byok type definitions

This commit is contained in:
Theodore Li
2026-02-13 10:18:37 -08:00
parent d174a6a3fb
commit c12e92c807
5 changed files with 9 additions and 34 deletions

View File

@@ -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')

View File

@@ -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

View File

@@ -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

View File

@@ -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') {

View File

@@ -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<string, unknown>) => number
}
/** Result from custom pricing calculation */
export interface CustomPricingResult {
/** Cost in dollars */
@@ -217,7 +208,6 @@ export interface CustomPricing<P = Record<string, unknown>, R extends ToolRespon
/** Union of all pricing models */
export type ToolHostingPricing<P = Record<string, unknown>, R extends ToolResponse = ToolResponse> =
| PerRequestPricing
| PerSecondPricing
| CustomPricing<P, R>
/**
@@ -229,8 +219,8 @@ export interface ToolHostingConfig<P = Record<string, unknown>, 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<P, R>
}