Member Junction
    Preparing search index...

    xAI implementation is just a sub-class of the OpenAILLM that overrides the base url

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _additionalSettings: Record<string, any>

    Protected property to store additional provider-specific settings

    activeStreamCancellationToken: AbortSignal

    Cancellation token for the in-flight streaming request, captured in createStreamingRequest so finalizeStreamingResponse can tell "the stream ended" from "the stream was aborted".

    protected rather than private because a subclass may override createStreamingRequest without calling super (Inception does, to send Mercury's divergent request payload). Such a subclass still inherits this class's finalizeStreamingResponse, so it must be able to stash the token — otherwise an aborted stream would finalize as a truncated success.

    thinkingStreamState: ThinkingStreamState

    State tracking for streaming thinking extraction Providers should initialize this if they support thinking models

    Accessors

    • get AdditionalSettings(): Record<string, any>

      Get the current additional settings

      Returns Record<string, any>

    • get apiKey(): string

      Only sub-classes can access the API key

      Returns string

    • get OpenAI(): OpenAI

      Read only getter method to get the OpenAI instance

      Returns OpenAI

    • get SupportsPrefill(): boolean

      Whether this LLM provider supports assistant prefill (pre-seeding the start of the model's response). Providers that support prefill should override this to return true. This is used as a code-level default when database metadata (AIModelType/AIModel/AIModelVendor.SupportsPrefill) is null. Database values of true/false override this getter.

      Returns boolean

    • get SupportsStreaming(): boolean

      OpenAI supports streaming

      Returns boolean

    Methods

    • Structured error info for a cancelled request. Cancellation is deliberate, so it is marked Fatal and non-failover-able — retrying or failing over to another vendor would defeat the cancellation. (AIErrorType has no dedicated cancellation member, so Unknown is used with an explicit provider error code.)

      Parameters

      • error: unknown

      Returns AIErrorInfo

    • Build the ChatResult returned when a request is cancelled mid-flight. Mirrors the shape of a failed ChatResult so callers see a clean, typed failure (success === false) instead of an unhandled rejection.

      Parameters

      • error: unknown
      • startTime: Date

      Returns ChatResult

    • Per-request options handed to the OpenAI SDK as the SECOND argument of chat.completions.create(body, options) — distinct from the request BODY.

      The only option we set today is signal, which carries ChatParams.cancellationToken down to the SDK's fetch call so an abort (caller cancellation or an AIPromptRunner timeout) actually tears down the HTTP socket instead of merely abandoning the promise. This is honored on BOTH the streaming and non-streaming paths.

      The SDK's own retry loop checks options.signal.aborted before every attempt and throws APIUserAbortError rather than retrying, so a cancelled request stays cancelled.

      Returned as a structural literal (rather than the SDK's RequestOptions, which is not exported from the package root) — every field of RequestOptions is optional, so this is assignable to it.

      Parameters

      Returns { signal?: AbortSignal }

    • Process a chat completion request. If streaming is enabled and supported, this will route to the streaming implementation.

      Parameters

      Returns Promise<ChatResult>

    • Process multiple chat completion requests in parallel. This is useful for:

      • Generating multiple variations with different parameters (temperature, etc.)
      • Getting multiple responses to compare or select from
      • Improving reliability by sending the same request multiple times

      Parameters

      Returns Promise<ChatResult[]>

      Promise resolving to an array of ChatResults in the same order as the input params

    • Clear all additional settings This is useful for resetting the state of the provider or when switching between different configurations.

      Returns void

    • Utility method to map a MemberJunction role to OpenAI role

      • system maps to system
      • user maps to user
      • assistant maps to assistant
      • anything else throws an error While the above is a direct 1:1 mapping, it is possible that OpenAI may have more roles in the future and this method will need to be updated for flexibility

      Parameters

      • role: string

      Returns "system" | "user" | "assistant"

    • Extract thinking content from non-streaming content This method handles case-insensitive extraction of thinking blocks

      Parameters

      • content: string

      Returns { content: string; thinking?: string }

    • Create the final response from streaming results for OpenAI

      Parameters

      • accumulatedContent: string
      • lastChunk: any
      • usage: any

      Returns ChatResult

    • OpenAI supports image file inputs natively via vision.

      Values reflect OpenAI's documented chat-completions vision API hard limits (https://platform.openai.com/docs/guides/images-vision):

      • 512 MB total payload per request
      • 1500 individual image inputs per request
      • Supported formats: PNG, JPEG, WEBP, non-animated GIF

      Note: the docs specify NO per-image size cap — only the request-level payload ceiling. We therefore set MaxFileSize to the same 512 MB value so this layer never rejects a single file OpenAI would accept; the effective constraint is that the SUM of all files in a request stays under 512 MB, which callers must enforce.

      These are API-level constraints — consistent across vision-capable chat models (gpt-4o, gpt-4.1, gpt-4-turbo, etc.), not per-model — so returning them from the shared driver is correct. Subclasses/wrappers that target non-standard endpoints (Azure OpenAI with its 50 MB cap, OpenAI-compatible gateways, etc.) should override this method if their limits differ.

      Returns FileCapabilities

    • Extra request-body params merged into BOTH the streaming and non-streaming ChatCompletion requests, beyond the standard OpenAI schema. Default is none. Subclasses targeting OpenAI-compatible gateways override this to opt into provider extensions the OpenAI SDK passes through verbatim — e.g. OpenRouter returns usage.cost / usage.cost_details only when usage: { include: true } is sent on the request.

      Parameters

      Returns Record<string, unknown>

    • Get the thinking tag format for this provider Providers can override this to customize the thinking tag format

      Returns { close: string; open: string }

    • Template method for handling streaming chat completion This implements the common pattern across providers while delegating provider-specific logic to abstract methods.

      Parameters

      Returns Promise<ChatResult>

    • Initialize thinking stream state for streaming extraction

      Returns void

    • True when error represents a cancellation of the request rather than a provider failure. Covers the SDK's typed APIUserAbortError, the DOM-standard AbortError, and the belt-and-braces case where the token is already aborted but the underlying transport surfaced some other error shape.

      Parameters

      • error: unknown
      • OptionalcancellationToken: AbortSignal

      Returns boolean

    • Process streaming chunk with thinking extraction This method handles case-insensitive extraction across chunk boundaries

      Parameters

      • rawContent: string

      Returns string

    • Process a streaming chunk from OpenAI

      Parameters

      • chunk: any

      Returns { content: string; finishReason?: string; usage?: any }

    • Reset streaming state for a new request. Overrides the base-class hook so BaseLLM.handleStreamingChatCompletion calls this both at the start of a request AND in its finally block — releasing accumulated reasoning/ thinking buffers and preventing state from a prior request bleeding into the next. Inheriting providers (Cerebras, Fireworks, Groq, xAI, Zhipu, Inception, LlamaCpp, etc.) automatically benefit from this override. See audit R2-C5.

      Returns void

    • Reset thinking stream state

      Returns void

    • Set additional provider-specific settings Subclasses should override this method to validate required settings

      Parameters

      • settings: Record<string, any>

        Provider-specific settings

      Returns void

    • Check if the provider supports thinking models Providers should override this to return true if they support thinking extraction

      Returns boolean