relayOpenAiCompletion function
Future<void>
relayOpenAiCompletion(
- LlmRelayRequest request,
- void onDelta(
- String delta
- Client? client,
- Duration? idleTimeout,
The real relay transport: one OpenAI-completions-dialect streaming
call — POST {baseUrl}/chat/completions with the injected key (none
for the anonymous mode), SSE deltas forwarded per chunk.
ponytail: openai-completions dialect only (the default custom-provider norm — openai/openrouter/zai/minimax/aiin/kimi endpoints; the catalog gate in resolveLlmRelayTarget enforces it by wire dialect, so brand-typed catalog names forward while anthropic/google/chatgpt- responses reject); other wire dialects answer with a clean llmRes error until a second dialect is actually needed.
Implementation
Future<void> relayOpenAiCompletion(
LlmRelayRequest request,
void Function(String delta) onDelta, {
http.Client? client,
Duration? idleTimeout,
}) async {
// The key is injected server-side; a null key is the ANONYMOUS relay
// mode — the call goes out with no Authorization header and can never
// carry a stored key (SEC-01).
final response = await sendProviderRequest(
client ?? sharedProviderHttpClient(),
_relayCall(request, request.key),
null,
);
await _forwardDeltas(
createSseIterator(response, null, idleTimeout: idleTimeout),
onDelta,
);
}