(params: {
body: ChatCompletionRequestBody
originalModel: string
fetch: typeof globalThis.fetch
})
| 49 | } |
| 50 | |
| 51 | function createSiliconFlowRequest(params: { |
| 52 | body: ChatCompletionRequestBody |
| 53 | originalModel: string |
| 54 | fetch: typeof globalThis.fetch |
| 55 | }) { |
| 56 | const { body, originalModel, fetch } = params |
| 57 | const siliconflowBody: Record<string, unknown> = { |
| 58 | ...body, |
| 59 | model: getSiliconFlowModelId(originalModel), |
| 60 | } |
| 61 | |
| 62 | // Strip OpenRouter-specific / internal fields |
| 63 | delete siliconflowBody.provider |
| 64 | delete siliconflowBody.transforms |
| 65 | delete siliconflowBody.codebuff_metadata |
| 66 | delete siliconflowBody.usage |
| 67 | |
| 68 | // For streaming, request usage in the final chunk |
| 69 | if (siliconflowBody.stream) { |
| 70 | siliconflowBody.stream_options = { include_usage: true } |
| 71 | } |
| 72 | |
| 73 | if (!env.SILICONFLOW_API_KEY) { |
| 74 | throw new Error('SILICONFLOW_API_KEY is not configured') |
| 75 | } |
| 76 | |
| 77 | return fetch(`${SILICONFLOW_BASE_URL}/chat/completions`, { |
| 78 | method: 'POST', |
| 79 | headers: { |
| 80 | Authorization: `Bearer ${env.SILICONFLOW_API_KEY}`, |
| 81 | 'Content-Type': 'application/json', |
| 82 | }, |
| 83 | body: JSON.stringify(siliconflowBody), |
| 84 | // @ts-expect-error - dispatcher is a valid undici option not in fetch types |
| 85 | dispatcher: siliconflowAgent, |
| 86 | }) |
| 87 | } |
| 88 | |
| 89 | // SiliconFlow per-token pricing (dollars per token) for MiniMax M2.5 |
| 90 | // https://siliconflow.com/pricing — $0.30/M input, $1.20/M output |
no test coverage detected