providerStreamFunction function

StreamFunction providerStreamFunction(
  1. String kind,
  2. String apiKey, {
  3. String? sessionId()?,
  4. String? cacheRetention,
  5. String? dialApiVersion,
  6. bool? dialCacheMarkersSupported,
  7. ChatGptCredentialsPersist? onChatGptCredentialsRefreshed,
})

Builds the StreamFunction for a provider adapter kind (openai-completions, minimax, zai, anthropic, google, dial, chatgpt-codex, copilot) with a static apiKey. Throws ConfigException for unknown kinds.

sessionId (resolved lazily per call) is the prompt-cache affinity key threaded to adapters that support one (OpenAI prompt_cache_key, OpenRouter x-session-id); cacheRetention sets the adapters' cache retention (short/long/none, adapter default when null). Both are defaults: an active StreamCacheRouting override (the compaction bypass) wins per call. dialApiVersion is the DIAL api-version query parameter (the dial kind only; omitted when null).

Implementation

StreamFunction providerStreamFunction(
  String kind,
  String apiKey, {
  String? Function()? sessionId,
  String? cacheRetention,
  String? dialApiVersion,
  bool? dialCacheMarkersSupported,
  ChatGptCredentialsPersist? onChatGptCredentialsRefreshed,
}) {
  if (kind != 'openai-completions' &&
      kind != 'anthropic' &&
      kind != 'google' &&
      kind != 'dial' &&
      kind != 'minimax' &&
      kind != 'zai' &&
      kind != 'aiin' &&
      kind != 'chatgpt-codex' &&
      kind != 'copilot') {
    throw ConfigException('Unknown provider kind: $kind');
  }
  // ignore: implicit_call_tearoffs
  final inner = _CatalogStreamFunction(
    kind,
    apiKey,
    sessionId,
    cacheRetention,
    dialApiVersion,
    dialCacheMarkersSupported,
    onChatGptCredentialsRefreshed,
  );
  // Every provider call (chat turns, compaction summaries, memory
  // extraction, media) rides the transient-network retry: a Wi-Fi switch
  // mid-turn dies with "Connection reset by peer" — sleep, replay.
  return transientRetryStreamFunction(inner.call);
}