MCPcopy
hub / github.com/TanStack/ai / createMistralClient

Function createMistralClient

packages/ai-mistral/src/utils/client.ts:20–40  ·  view source on GitHub ↗
(config: MistralClientConfig)

Source from the content-addressed store, hash-verified

18 * Creates a Mistral SDK client instance.
19 */
20export function createMistralClient(config: MistralClientConfig): Mistral {
21 const { apiKey, serverURL, timeoutMs, defaultHeaders } = config
22
23 let httpClient: HTTPClient | undefined
24 if (defaultHeaders && Object.keys(defaultHeaders).length > 0) {
25 httpClient = new HTTPClient()
26 httpClient.addHook('beforeRequest', (req) => {
27 for (const [key, value] of Object.entries(defaultHeaders)) {
28 req.headers.set(key, value)
29 }
30 return req
31 })
32 }
33
34 return new Mistral({
35 apiKey,
36 ...(serverURL !== undefined ? { serverURL } : {}),
37 ...(timeoutMs !== undefined ? { timeoutMs } : {}),
38 ...(httpClient !== undefined ? { httpClient } : {}),
39 })
40}
41
42/**
43 * Gets Mistral API key from environment variables.

Callers 1

constructorMethod · 0.90

Calls 2

addHookMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected