Skip to content

Commit ee2e123

Browse files
author
Theodore Li
committed
Fail loudly if cost field isn't found
1 parent 8eaf401 commit ee2e123

File tree

4 files changed

+13
-47
lines changed

4 files changed

+13
-47
lines changed

apps/sim/tools/exa/answer.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import { createLogger } from '@sim/logger'
21
import type { ExaAnswerParams, ExaAnswerResponse } from '@/tools/exa/types'
32
import type { ToolConfig } from '@/tools/types'
43

5-
const logger = createLogger('ExaAnswerTool')
6-
74
export const answerTool: ToolConfig<ExaAnswerParams, ExaAnswerResponse> = {
85
id: 'exa_answer',
96
name: 'Exa Answer',
@@ -37,14 +34,11 @@ export const answerTool: ToolConfig<ExaAnswerParams, ExaAnswerResponse> = {
3734
pricing: {
3835
type: 'custom',
3936
getCost: (_params, output) => {
40-
// Use __costDollars from Exa API response (internal field, stripped from final output)
4137
const costDollars = output.__costDollars as { total?: number } | undefined
42-
if (costDollars?.total != null) {
43-
return { cost: costDollars.total, metadata: { costDollars } }
38+
if (costDollars?.total == null) {
39+
throw new Error('Exa answer response missing costDollars field')
4440
}
45-
// Fallback: $5/1000 requests
46-
logger.warn('Exa answer response missing costDollars, using fallback pricing')
47-
return 0.005
41+
return { cost: costDollars.total, metadata: { costDollars } }
4842
},
4943
},
5044
rateLimit: {

apps/sim/tools/exa/find_similar_links.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import { createLogger } from '@sim/logger'
21
import type { ExaFindSimilarLinksParams, ExaFindSimilarLinksResponse } from '@/tools/exa/types'
32
import type { ToolConfig } from '@/tools/types'
43

5-
const logger = createLogger('ExaFindSimilarLinksTool')
6-
74
export const findSimilarLinksTool: ToolConfig<
85
ExaFindSimilarLinksParams,
96
ExaFindSimilarLinksResponse
@@ -86,16 +83,11 @@ export const findSimilarLinksTool: ToolConfig<
8683
pricing: {
8784
type: 'custom',
8885
getCost: (_params, output) => {
89-
// Use __costDollars from Exa API response (internal field, stripped from final output)
9086
const costDollars = output.__costDollars as { total?: number } | undefined
91-
if (costDollars?.total != null) {
92-
return { cost: costDollars.total, metadata: { costDollars } }
87+
if (costDollars?.total == null) {
88+
throw new Error('Exa find_similar_links response missing costDollars field')
9389
}
94-
// Fallback: $5/1000 (1-25 results) or $25/1000 (26-100 results)
95-
logger.warn('Exa find_similar_links response missing costDollars, using fallback pricing')
96-
const similarLinks = output.similarLinks as unknown[] | undefined
97-
const resultCount = similarLinks?.length || 0
98-
return resultCount <= 25 ? 0.005 : 0.025
90+
return { cost: costDollars.total, metadata: { costDollars } }
9991
},
10092
},
10193
rateLimit: {

apps/sim/tools/exa/get_contents.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import { createLogger } from '@sim/logger'
21
import type { ExaGetContentsParams, ExaGetContentsResponse } from '@/tools/exa/types'
32
import type { ToolConfig } from '@/tools/types'
43

5-
const logger = createLogger('ExaGetContentsTool')
6-
74
export const getContentsTool: ToolConfig<ExaGetContentsParams, ExaGetContentsResponse> = {
85
id: 'exa_get_contents',
96
name: 'Exa Get Contents',
@@ -71,15 +68,11 @@ export const getContentsTool: ToolConfig<ExaGetContentsParams, ExaGetContentsRes
7168
pricing: {
7269
type: 'custom',
7370
getCost: (_params, output) => {
74-
// Use __costDollars from Exa API response (internal field, stripped from final output)
7571
const costDollars = output.__costDollars as { total?: number } | undefined
76-
if (costDollars?.total != null) {
77-
return { cost: costDollars.total, metadata: { costDollars } }
72+
if (costDollars?.total == null) {
73+
throw new Error('Exa get_contents response missing costDollars field')
7874
}
79-
// Fallback: $1/1000 pages
80-
logger.warn('Exa get_contents response missing costDollars, using fallback pricing')
81-
const results = output.results as unknown[] | undefined
82-
return (results?.length || 0) * 0.001
75+
return { cost: costDollars.total, metadata: { costDollars } }
8376
},
8477
},
8578
rateLimit: {

apps/sim/tools/exa/search.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import { createLogger } from '@sim/logger'
21
import type { ExaSearchParams, ExaSearchResponse } from '@/tools/exa/types'
32
import type { ToolConfig } from '@/tools/types'
43

5-
const logger = createLogger('ExaSearchTool')
6-
74
export const searchTool: ToolConfig<ExaSearchParams, ExaSearchResponse> = {
85
id: 'exa_search',
96
name: 'Exa Search',
@@ -95,22 +92,12 @@ export const searchTool: ToolConfig<ExaSearchParams, ExaSearchResponse> = {
9592
byokProviderId: 'exa',
9693
pricing: {
9794
type: 'custom',
98-
getCost: (params, output) => {
99-
// Use __costDollars from Exa API response (internal field, stripped from final output)
95+
getCost: (_params, output) => {
10096
const costDollars = output.__costDollars as { total?: number } | undefined
101-
if (costDollars?.total != null) {
102-
return { cost: costDollars.total, metadata: { costDollars } }
103-
}
104-
105-
// Fallback: estimate based on search type and result count
106-
logger.warn('Exa search response missing costDollars, using fallback pricing')
107-
const isDeepSearch = params.type === 'neural'
108-
if (isDeepSearch) {
109-
return 0.015
97+
if (costDollars?.total == null) {
98+
throw new Error('Exa search response missing costDollars field')
11099
}
111-
const results = output.results as unknown[] | undefined
112-
const resultCount = results?.length || 0
113-
return resultCount <= 25 ? 0.005 : 0.025
100+
return { cost: costDollars.total, metadata: { costDollars } }
114101
},
115102
},
116103
rateLimit: {

0 commit comments

Comments
 (0)