Architecture
The provider maps the abstract engine onto the OpenAI Chat Completions API.
Provider boundary
OpenAIChatService extends the abstract ChatService from
@johannes.latzel/llm-chat. The base class owns the chat history, message
queue, tool-call loop, hooks, stream aggregation and prompt loading.
flowchart LR
accTitle: Provider request and response flow
accDescr: OpenAIChatService maps the abstract conversation and neutral tool definitions to OpenAI request messages and function tools, sends them through the OpenAI SDK, and yields provider-neutral StreamEvent values back to the base ChatService.
engine["ChatService<br/>llm-chat"] -->|"chat + ToolDefinition"| provider["OpenAIChatService<br/>this package"]
provider -->|"request"| sdk["OpenAI SDK"]
sdk -->|"HTTP"| api["OpenAI-compatible API"]
api -->|"chunks"| sdk
sdk -->|"response"| provider
provider -->|"StreamEvent"| engine
The provider implements createStream(signal) and yields provider-neutral
StreamEvent values: content, reasoning, refusal, tool-call delta, usage and
finish.
Request mapping
ChatMessageroles map to OpenAIsystem,developer,user,assistantandtoolroles.- Reasoning messages are filtered from outgoing requests when
filterReasoningis enabled (the default). An unfilteredChatRole.Reasoningmessage is sent with theassistantrole. - The provider formats the timestamp prefix for conversation messages in
its
toOutgoingContentoverride; system prompts are never prefixed. The base class calls that hook for outgoing content and token estimates. - Registered tools are read from
ToolSuite.getDefinitions()as neutralToolDefinitionvalues and converted withtoOpenAIFunctionTools()before the request.
Response mapping
finish_reasonmaps toFinishReason, includingcontent_filter.delta.contentbecomes content events.delta.refusalbecomes refusal events.- Reasoning is read from
reasoning_details,reasoningorreasoning_contentin priority order. - Tool-call deltas are forwarded without accumulation; the base service accumulates them.
Structured output
The responseFormat option is passed through as response_format. The
provider does not rewrite or validate the schema. Parsing and validation of
assistant JSON happen in the base service.
Configuration
OpenAIChatServiceConfiguration reads LLM_CHAT_OPENAI_* environment
variables in field initializers and accepts builder overrides or a configuration object passed to the service constructor.
The shared @johannes.latzel/env reader clamps the numeric token limits
(maxTokens, maxCompletionTokens) and trims optional strings; temperature
and topP are read as unbounded numbers. See Environment variables.