nimgent/providers/openai_chat
This page is generated from the module’s exported API and ## documentation comments.
Chat Completions wire format (OpenRouter, Hyper, OpenAI-compat).
ChatReasoning
Section titled “ChatReasoning”How an OpenAI-compatible Chat host wants replayed assistant thinking.
ChatReasoning = enum crReasoning, ## `reasoning` plus `reasoning_details` (OpenRouter style). crReasoningContent ## `reasoning_content`, required back by thinking-mode hosts.Procedures
Section titled “Procedures”openAiImagePart
Section titled “openAiImagePart”Encode an image as an OpenAI-compatible chat content part.
proc openAiImagePart(mimeType, data: string): JsonNode {.raises: [], tags: [], forbids: [].}Returns: JsonNode.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
mimeType |
string |
|
data |
string |
buildChatBody
Section titled “buildChatBody”Build an OpenAI-compatible Chat Completions request body.
proc buildChatBody(request: ProviderRequest; stream: bool; includeConversationId = false; applyCache = false; maxTokensField = "max_completion_tokens"; promptCacheKey = ""; reasoning = crReasoning): JsonNode {. raises: [ProviderError, KeyError], tags: [ReadIOEffect, WriteIOEffect], forbids: [].}Returns: JsonNode.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
request |
ProviderRequest |
|
stream |
bool |
|
includeConversationId |
inferred |
false |
applyCache |
inferred |
false |
maxTokensField |
inferred |
"max_completion_tokens" |
promptCacheKey |
inferred |
"" |
reasoning |
inferred |
crReasoning |
chatObjectOptions
Section titled “chatObjectOptions”Build Chat Completions options for native JSON schema output.
proc chatObjectOptions(name, description: string; schema: JsonNode): JsonNode {. raises: [], tags: [], forbids: [].}Returns: JsonNode.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
name |
string |
|
description |
string |
|
schema |
JsonNode |
parseChatOutput
Section titled “parseChatOutput”Parse an OpenAI-compatible Chat Completions response.
proc parseChatOutput(data: JsonNode; failPrefix: string): ProviderResponse {. raises: [KeyError, ProviderError], tags: [ReadIOEffect, WriteIOEffect], forbids: [].}Returns: ProviderResponse.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
data |
JsonNode |
|
failPrefix |
string |
handleChatEvent
Section titled “handleChatEvent”Consume one Chat Completions SSE event.
proc handleChatEvent(acc: var StreamAcc; response: var ProviderResponse; data: JsonNode; onEvent: StreamCallback): SseAction {. raises: [KeyError, Exception], tags: [RootEffect], forbids: [].}Returns: SseAction.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
acc |
var StreamAcc |
|
response |
var ProviderResponse |
|
data |
JsonNode |
|
onEvent |
StreamCallback |