MCPcopy Create free account
hub / github.com/Noumena-Network/code / executeNonStreamingRequest

Function executeNonStreamingRequest

src/services/api/claude.ts:845–944  ·  view source on GitHub ↗
(
  clientOptions: {
    model: string
    fetchOverride?: Options['fetchOverride']
    source: string
  },
  retryOptions: {
    model: string
    fallbackModel?: string
    thinkingConfig: ThinkingConfig
    fastMode?: boolean
    signal: AbortSignal
    initialConsecutive529Errors?: number
    querySource?: QuerySource
  },
  paramsFromContext: (context: RetryContext) => BetaMessageStreamParams,
  onAttempt: (attempt: number, start: number, maxOutputTokens: number) => void,
  captureRequest: (params: BetaMessageStreamParams) => void,
  /**
   * Request ID of the failed streaming attempt this fallback is recovering
   * from. Emitted in ncode_nonstreaming_fallback_error for funnel correlation.
   */
  originatingRequestId?: string | null,
)

Source from the content-addressed store, hash-verified

843 * iterating to yield system messages, and returning the final BetaMessage.
844 */
845export async function* executeNonStreamingRequest(
846 clientOptions: {
847 model: string
848 fetchOverride?: Options['fetchOverride']
849 source: string
850 },
851 retryOptions: {
852 model: string
853 fallbackModel?: string
854 thinkingConfig: ThinkingConfig
855 fastMode?: boolean
856 signal: AbortSignal
857 initialConsecutive529Errors?: number
858 querySource?: QuerySource
859 },
860 paramsFromContext: (context: RetryContext) => BetaMessageStreamParams,
861 onAttempt: (attempt: number, start: number, maxOutputTokens: number) => void,
862 captureRequest: (params: BetaMessageStreamParams) => void,
863 /**
864 * Request ID of the failed streaming attempt this fallback is recovering
865 * from. Emitted in ncode_nonstreaming_fallback_error for funnel correlation.
866 */
867 originatingRequestId?: string | null,
868): AsyncGenerator<SystemAPIErrorMessage, BetaMessage> {
869 const fallbackTimeoutMs = getNonstreamingFallbackTimeoutMs()
870 const generator = withRetry(
871 () =>
872 getInferenceClient({
873 maxRetries: 0,
874 model: clientOptions.model,
875 fetchOverride: clientOptions.fetchOverride,
876 source: clientOptions.source,
877 }),
878 async (inferenceClient, attempt, context) => {
879 const start = Date.now()
880 const retryParams = paramsFromContext(context)
881 captureRequest(retryParams)
882 onAttempt(attempt, start, retryParams.max_tokens)
883
884 const adjustedParams = adjustParamsForNonStreaming(
885 retryParams,
886 MAX_NON_STREAMING_TOKENS,
887 )
888
889 try {
890 // biome-ignore lint/plugin: non-streaming API call
891 return await inferenceClient.createMessage(
892 {
893 ...adjustedParams,
894 model: normalizeModelStringForAPI(adjustedParams.model),
895 },
896 {
897 signal: retryOptions.signal,
898 timeout: fallbackTimeoutMs,
899 },
900 )
901 } catch (err) {
902 // User aborts are not errors — re-throw immediately without logging

Callers 1

queryModelFunction · 0.85

Calls 11

getInferenceClientFunction · 0.85
paramsFromContextFunction · 0.85
logForDiagnosticsNoPIIFunction · 0.85
isFastModeEnabledFunction · 0.85
withRetryFunction · 0.70
logEventFunction · 0.70
createMessageMethod · 0.65
nextMethod · 0.45

Tested by

no test coverage detected