({
systemPrompt = asSystemPrompt([]),
userPrompt,
outputFormat,
signal,
options,
}: {
systemPrompt: SystemPrompt
userPrompt: string
outputFormat?: BetaJSONOutputFormat
signal: AbortSignal
options: QueryWithModelOptions
})
| 3298 | * betas, and headers - unlike direct API calls. |
| 3299 | */ |
| 3300 | export async function queryWithModel({ |
| 3301 | systemPrompt = asSystemPrompt([]), |
| 3302 | userPrompt, |
| 3303 | outputFormat, |
| 3304 | signal, |
| 3305 | options, |
| 3306 | }: { |
| 3307 | systemPrompt: SystemPrompt |
| 3308 | userPrompt: string |
| 3309 | outputFormat?: BetaJSONOutputFormat |
| 3310 | signal: AbortSignal |
| 3311 | options: QueryWithModelOptions |
| 3312 | }): Promise<AssistantMessage> { |
| 3313 | const result = await withVCR( |
| 3314 | [ |
| 3315 | createUserMessage({ |
| 3316 | content: systemPrompt.map(text => ({ type: 'text', text })), |
| 3317 | }), |
| 3318 | createUserMessage({ |
| 3319 | content: userPrompt, |
| 3320 | }), |
| 3321 | ], |
| 3322 | async () => { |
| 3323 | const messages = [ |
| 3324 | createUserMessage({ |
| 3325 | content: userPrompt, |
| 3326 | }), |
| 3327 | ] |
| 3328 | |
| 3329 | const result = await queryModelWithoutStreaming({ |
| 3330 | messages, |
| 3331 | systemPrompt, |
| 3332 | thinkingConfig: { type: 'disabled' }, |
| 3333 | tools: [], |
| 3334 | signal, |
| 3335 | options: { |
| 3336 | ...options, |
| 3337 | enablePromptCaching: options.enablePromptCaching ?? false, |
| 3338 | outputFormat, |
| 3339 | async getToolPermissionContext() { |
| 3340 | return getEmptyToolPermissionContext() |
| 3341 | }, |
| 3342 | }, |
| 3343 | }) |
| 3344 | return [result] |
| 3345 | }, |
| 3346 | ) |
| 3347 | return result[0]! as AssistantMessage |
| 3348 | } |
| 3349 | |
| 3350 | // Non-streaming requests have a 10min max per the docs: |
| 3351 | // https://platform.claude.com/docs/en/api/errors#long-requests |
no test coverage detected