MCPcopy
hub / github.com/simstudioai/sim / resolveCohereKey

Function resolveCohereKey

apps/sim/lib/knowledge/reranker.ts:47–77  ·  view source on GitHub ↗
(
  workspaceId?: string | null,
  userApiKey?: string
)

Source from the content-addressed store, hash-verified

45}
46
47async function resolveCohereKey(
48 workspaceId?: string | null,
49 userApiKey?: string
50): Promise<{ apiKey: string; isBYOK: boolean }> {
51 /**
52 * Mirrors the agent block hosted-key pattern (`injectHostedKeyIfNeeded`):
53 * on self-hosted the user-supplied key from the block field flows through
54 * unchanged; on hosted Sim we always source the key from workspace BYOK or
55 * platform env, so any user-supplied value is ignored.
56 */
57 if (!isHosted && userApiKey) {
58 return { apiKey: userApiKey, isBYOK: false }
59 }
60 if (workspaceId) {
61 const byokResult = await getBYOKKey(workspaceId, 'cohere')
62 if (byokResult) {
63 logger.info('Using workspace BYOK key for Cohere reranker')
64 return { apiKey: byokResult.apiKey, isBYOK: true }
65 }
66 }
67 if (env.COHERE_API_KEY) {
68 return { apiKey: env.COHERE_API_KEY, isBYOK: false }
69 }
70 try {
71 return { apiKey: getRotatingApiKey('cohere'), isBYOK: false }
72 } catch {
73 throw new Error(
74 'No Cohere API key configured. Set COHERE_API_KEY_1/2/3 (rotation) or COHERE_API_KEY.'
75 )
76 }
77}
78
79/**
80 * Subset of Cohere v2/rerank response fields we read.

Callers 1

rerankFunction · 0.85

Calls 3

getBYOKKeyFunction · 0.90
getRotatingApiKeyFunction · 0.90
infoMethod · 0.80

Tested by

no test coverage detected