MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / executeNonStreamingRequest

Function executeNonStreamingRequest

src/services/api/claude.ts:841–939  ·  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 tengu_nonstreaming_fallback_error for funnel correlation.
   */
  originatingRequestId?: string | null,
)

Source from the content-addressed store, hash-verified

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

Callers 1

queryModelFunction · 0.85

Calls 12

getAnthropicClientFunction · 0.85
paramsFromContextFunction · 0.85
logForDiagnosticsNoPIIFunction · 0.85
logEventFunction · 0.85
isFastModeEnabledFunction · 0.85
nowMethod · 0.80
nextMethod · 0.80
withRetryFunction · 0.70
createMethod · 0.65

Tested by

no test coverage detected