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

Function applyResponseFormat

apps/sim/providers/openrouter/index.ts:41–68  ·  view source on GitHub ↗

* Applies structured output configuration to a payload based on model capabilities. * Uses json_schema with require_parameters for supported models, falls back to json_object with prompt instructions.

(
  targetPayload: any,
  messages: any[],
  responseFormat: any,
  model: string
)

Source from the content-addressed store, hash-verified

39 * Uses json_schema with require_parameters for supported models, falls back to json_object with prompt instructions.
40 */
41async function applyResponseFormat(
42 targetPayload: any,
43 messages: any[],
44 responseFormat: any,
45 model: string
46): Promise<any[]> {
47 const useNative = await supportsNativeStructuredOutputs(model)
48
49 if (useNative) {
50 logger.info('Using native structured outputs for OpenRouter model', { model })
51 targetPayload.response_format = {
52 type: 'json_schema',
53 json_schema: {
54 name: responseFormat.name || 'response_schema',
55 schema: responseFormat.schema || responseFormat,
56 strict: responseFormat.strict !== false,
57 },
58 }
59 targetPayload.provider = { ...targetPayload.provider, require_parameters: true }
60 return messages
61 }
62
63 logger.info('Using json_object mode with prompt instructions for OpenRouter model', { model })
64 const schema = responseFormat.schema || responseFormat
65 const schemaInstructions = generateSchemaInstructions(schema, responseFormat.name)
66 targetPayload.response_format = { type: 'json_object' }
67 return [...messages, { role: 'user', content: schemaInstructions }]
68}
69
70export const openRouterProvider: ProviderConfig = {
71 id: 'openrouter',

Callers 1

index.tsFile · 0.70

Calls 3

infoMethod · 0.80

Tested by

no test coverage detected