Skip to content

Commit a463ebc

Browse files
author
Theodore Li
committed
Add mistral hosted key
1 parent 9f676bc commit a463ebc

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

apps/sim/blocks/blocks/mistral_parse.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,22 +327,22 @@ export const MistralParseV3Block: BlockConfig<MistralParserOutput> = {
327327
placeholder: 'Enter your Mistral API key',
328328
password: true,
329329
required: true,
330+
hideWhenHosted: true,
330331
},
331332
],
332333
tools: {
333334
access: ['mistral_parser_v3'],
334335
config: {
335336
tool: () => 'mistral_parser_v3',
336337
params: (params) => {
337-
if (!params || !params.apiKey || params.apiKey.trim() === '') {
338-
throw new Error('Mistral API key is required')
339-
}
340-
341338
const parameters: Record<string, unknown> = {
342-
apiKey: params.apiKey.trim(),
343339
resultType: params.resultType || 'markdown',
344340
}
345341

342+
if (params.apiKey?.trim()) {
343+
parameters.apiKey = params.apiKey.trim()
344+
}
345+
346346
// V3 pattern: use canonical document param directly
347347
const documentInput = normalizeFileInput(params.document, { single: true })
348348
if (!documentInput) {

apps/sim/tools/mistral/parser.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,29 @@ import type { ToolConfig } from '@/tools/types'
1010

1111
const logger = createLogger('MistralParserTool')
1212

13+
const MISTRAL_OCR_HOSTING = {
14+
envKeyPrefix: 'MISTRAL_API_KEY',
15+
apiKeyParam: 'apiKey',
16+
byokProviderId: 'mistral' as const,
17+
pricing: {
18+
type: 'custom' as const,
19+
getCost: (_params: Record<string, unknown>, output: Record<string, unknown>) => {
20+
// Mistral OCR: $1 per 1,000 pages ($0.001/page) — https://mistral.ai/pricing
21+
const usageInfo = output.usage_info as { pages_processed?: number } | undefined
22+
if (usageInfo?.pages_processed == null) {
23+
throw new Error('Mistral OCR response missing pages_processed in usage_info')
24+
}
25+
const pagesProcessed = usageInfo.pages_processed
26+
const cost = pagesProcessed * 0.001
27+
return { cost, metadata: { pagesProcessed } }
28+
},
29+
},
30+
rateLimit: {
31+
mode: 'per_request' as const,
32+
requestsPerMinute: 60,
33+
},
34+
}
35+
1336
export const mistralParserTool: ToolConfig<MistralParserInput, MistralParserOutput> = {
1437
id: 'mistral_parser',
1538
name: 'Mistral PDF Parser',
@@ -492,6 +515,7 @@ export const mistralParserV3Tool: ToolConfig<MistralParserV2Input, MistralParser
492515
...mistralParserV2Tool,
493516
id: 'mistral_parser_v3',
494517
version: '3.0.0',
518+
hosting: MISTRAL_OCR_HOSTING,
495519
params: {
496520
file: {
497521
type: 'file',

0 commit comments

Comments
 (0)