MCPcopy Index your code
hub / github.com/simstudioai/sim / executeProviderRequest

Function executeProviderRequest

apps/sim/providers/index.ts:130–266  ·  view source on GitHub ↗
(
  providerId: string,
  request: ProviderRequest
)

Source from the content-addressed store, hash-verified

128}
129
130export async function executeProviderRequest(
131 providerId: string,
132 request: ProviderRequest
133): Promise<ProviderResponse | ReadableStream | StreamingExecution> {
134 const provider = await getProviderExecutor(providerId as ProviderId)
135 if (!provider) {
136 throw new Error(`Provider not found: ${providerId}`)
137 }
138
139 if (!provider.executeRequest) {
140 throw new Error(`Provider ${providerId} does not implement executeRequest`)
141 }
142
143 let resolvedRequest = sanitizeRequest(request)
144 let isBYOK = false
145
146 if (request.workspaceId) {
147 try {
148 const result = await getApiKeyWithBYOK(
149 providerId,
150 request.model,
151 request.workspaceId,
152 request.apiKey
153 )
154 resolvedRequest = { ...resolvedRequest, apiKey: result.apiKey }
155 isBYOK = result.isBYOK
156 logger.info('API key resolved', {
157 provider: providerId,
158 model: request.model,
159 workspaceId: request.workspaceId,
160 isBYOK,
161 })
162 } catch (error) {
163 logger.error('Failed to resolve API key:', {
164 provider: providerId,
165 model: request.model,
166 error: toError(error).message,
167 })
168 throw error
169 }
170 }
171
172 resolvedRequest.isBYOK = isBYOK
173 const sanitizedRequest = resolvedRequest
174
175 if (sanitizedRequest.responseFormat) {
176 if (
177 typeof sanitizedRequest.responseFormat === 'string' &&
178 sanitizedRequest.responseFormat === ''
179 ) {
180 logger.info('Empty response format provided, ignoring it')
181 sanitizedRequest.responseFormat = undefined
182 } else {
183 const structuredOutputInstructions = generateStructuredOutputInstructions(
184 sanitizedRequest.responseFormat
185 )
186
187 if (structuredOutputInstructions.trim()) {

Callers 4

index.test.tsFile · 0.90
route.tsFile · 0.90

Calls 15

getProviderExecutorFunction · 0.90
getApiKeyWithBYOKFunction · 0.90
toErrorFunction · 0.90
shouldBillModelUsageFunction · 0.90
getCostMultiplierFunction · 0.90
calculateCostFunction · 0.90
sumToolCostsFunction · 0.90
sanitizeRequestFunction · 0.85
isStreamingExecutionFunction · 0.85

Tested by

no test coverage detected