(content)
| 618 | ); |
| 619 | |
| 620 | if (window.networkLogger) { |
| 621 | window.networkLogger.logRequest({ |
| 622 | type: 'openrouter', |
| 623 | method: 'POST', |
| 624 | url, |
| 625 | status: response.status, |
| 626 | sessionId: sessionId || undefined, |
| 627 | keyRef: window.networkLogger.keyRefForHeaders(headers), |
| 628 | request: { |
| 629 | headers: window.networkLogger.sanitizeHeaders(headers), |
| 630 | body: { |
| 631 | model: titleModelId, |
| 632 | messages: 'title generation', |
| 633 | max_tokens: body.max_tokens, |
| 634 | temperature: body.temperature |
| 635 | } |
| 636 | }, |
| 637 | response: response.ok ? { titleGeneration: true } : data || text |
| 638 | }); |
| 639 | } |
| 640 | |
| 641 | if (!response.ok) { |
| 642 | const errorMessage = getErrorMessage(data?.error, getErrorMessage(data, `HTTP error! status: ${response.status}`)); |
| 643 | const error = new Error(errorMessage); |
| 644 | error.status = response.status; |
| 645 | error.data = data; |
| 646 | throw error; |
| 647 | } |
| 648 | markInferenceKeyAccepted(bearerToken(headers)); |
| 649 | |
| 650 | if (data?.usage && typeof options.onUsage === 'function') { |
| 651 | try { |
| 652 | await options.onUsage({ |
| 653 | totalTokens: Number(data.usage.total_tokens ?? |
| 654 | (Number(data.usage.prompt_tokens || 0) + Number(data.usage.completion_tokens || 0))), |
| 655 | promptTokens: Number(data.usage.prompt_tokens || 0), |
| 656 | completionTokens: Number(data.usage.completion_tokens || 0), |
| 657 | cost: data.usage.cost, |
| 658 | model: data.model || titleModelId, |
| 659 | pricing: this.getModelBudgetMetadata(data.model || titleModelId)?.pricing |
| 660 | || null |
| 661 | }); |
| 662 | } catch (usageError) { |
| 663 | console.warn('Could not record title usage:', usageError); |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | return data?.choices?.[0]?.message?.content || ''; |
| 668 | } catch (error) { |
| 669 | throw error; |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | // Stream chat completion with support for multimodal content, web search, and reasoning traces |
| 674 | async _streamCompletion(messages, modelId, sessionId, onChunk, onTokenUpdate, files = [], searchEnabled = false, abortController = null, onStreamOpen = null, onReasoningChunk = null, reasoningEnabled = true, reasoningEffort = DEFAULT_REASONING_EFFORT, onAccessProgress = null, onStreamHealth = null) { |
| 675 | |
| 676 | // Handle web search - append :online suffix if enabled |
| 677 | let effectiveModelId = modelId; |
nothing calls this directly
no outgoing calls
no test coverage detected