nimgent/providers/anthropic
This page is generated from the module’s exported API and ## documentation comments.
Anthropic Messages API adapter.
Constants
Section titled “Constants”defaultAnthropicEndpoint
Section titled “defaultAnthropicEndpoint”Default Anthropic Messages endpoint.
defaultAnthropicEndpoint = "https://api.anthropic.com/v1/messages"Procedures
Section titled “Procedures”anthropicEfforts
Section titled “anthropicEfforts”Explicit known families; unknown models retain manual thinking support.
proc anthropicEfforts(model: string): seq[string] {.raises: [], tags: [], forbids: [].}Returns: seq[string].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
string |
anthropicThinkingOptions
Section titled “anthropicThinkingOptions”Convert a thinking level to Anthropic request options.
proc anthropicThinkingOptions(model, level: string): JsonNode {. raises: [ValueError], tags: [], forbids: [].}Returns: JsonNode.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
string |
|
level |
string |
anthropicImageBlock
Section titled “anthropicImageBlock”Encode base64 image data as an Anthropic content block.
proc anthropicImageBlock(mimeType, data: string): JsonNode {.raises: [], tags: [], forbids: [].}Returns: JsonNode.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
mimeType |
string |
|
data |
string |
anthropicDocument
Section titled “anthropicDocument”Encode file content as an Anthropic document block.
proc anthropicDocument(f: FileContent): JsonNode {.raises: [], tags: [], forbids: [].}Returns: JsonNode.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
f |
FileContent |
parseAnthropicOutput
Section titled “parseAnthropicOutput”Parse an Anthropic Messages response.
proc parseAnthropicOutput(data: JsonNode): ProviderResponse {. raises: [ProviderError, KeyError], tags: [], forbids: [].}Returns: ProviderResponse.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
data |
JsonNode |
anthropic
Section titled “anthropic”Create an Anthropic provider.
proc anthropic(apiKey: string; endpoint = ""; timeoutSeconds = 300; sessionHeader = ""; userAgent = ""): AnthropicProvider {. raises: [], tags: [], forbids: [].}Returns: AnthropicProvider.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
apiKey |
string |
|
endpoint |
inferred |
"" |
timeoutSeconds |
inferred |
300 |
sessionHeader |
inferred |
"" |
userAgent |
inferred |
"" |
buildAnthropicBody
Section titled “buildAnthropicBody”Build an Anthropic Messages request body.
proc buildAnthropicBody(request: ProviderRequest): JsonNode {. raises: [ProviderError, KeyError], tags: [ReadIOEffect, WriteIOEffect], forbids: [].}Returns: JsonNode.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
request |
ProviderRequest |
handleAnthropicEvent
Section titled “handleAnthropicEvent”Consume one Anthropic Messages SSE event.
proc handleAnthropicEvent(message: var JsonNode; args: var seq[string]; data: JsonNode; onEvent: StreamCallback): SseAction {. raises: [KeyError, Exception, ProviderError], tags: [RootEffect, ReadIOEffect, WriteIOEffect], forbids: [].}Returns: SseAction.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
message |
var JsonNode |
|
args |
var seq[string] |
|
data |
JsonNode |
|
onEvent |
StreamCallback |
toProviderJson
Section titled “toProviderJson”Serialize Anthropic-specific request options.
proc toProviderJson(value: AnthropicOptions): JsonNode {. raises: [ProviderError, KeyError], tags: [], forbids: [].}Returns: JsonNode.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
value |
AnthropicOptions |
AnthropicProvider
Section titled “AnthropicProvider”Anthropic Messages provider configuration.
AnthropicProvider = ref object of Provider endpoint*: string userAgent*: string ## Header carrying a stable conversation id; empty sends none. OpenCode Zen's ## gateway requires `x-opencode-session` on its Messages endpoint. sessionHeader*: stringAnthropicThinking
Section titled “AnthropicThinking”Anthropic thinking mode.
AnthropicThinking = enum DisabledThinking = "disabled", AdaptiveThinking = "adaptive", EnabledThinking = "enabled"AnthropicOptions
Section titled “AnthropicOptions”Anthropic-specific structured and thinking settings.
AnthropicOptions = object thinking*: Option[AnthropicThinking] budgetTokens*: Option[int] ## Required with EnabledThinking.Methods
Section titled “Methods”nativeObjectOptions
Section titled “nativeObjectOptions”Return Anthropic native structured-output options.
method nativeObjectOptions(provider: AnthropicProvider; model, name, description: string; schema: JsonNode): JsonNode {. raises: [], tags: [], forbids: [].}Returns: JsonNode.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
provider |
AnthropicProvider |
|
model |
string |
|
name |
string |
|
description |
string |
|
schema |
JsonNode |
generateAsync
Section titled “generateAsync”Send a request through the Anthropic Messages API.
method generateAsync(provider: AnthropicProvider; request: ProviderRequest): Future[ ProviderResponse] {.stackTrace: false, raises: [Exception, ValueError, ProviderError, KeyError, LibraryError, SslError, IOError], tags: [ RootEffect, ReadIOEffect, WriteIOEffect, ReadDirEffect, ReadEnvEffect, TimeEffect], forbids: [].}Returns: Future[ProviderResponse].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
provider |
AnthropicProvider |
|
request |
ProviderRequest |
generateStreamAsync
Section titled “generateStreamAsync”Stream a request through the Anthropic Messages API.
method generateStreamAsync(provider: AnthropicProvider; request: ProviderRequest; onEvent: StreamCallback): Future[ ProviderResponse] {.stackTrace: false, raises: [Exception, ValueError, ProviderError, LibraryError, SslError, IOError, KeyError], tags: [ RootEffect, ReadDirEffect, ReadEnvEffect, ReadIOEffect, WriteIOEffect, TimeEffect], forbids: [].}Returns: Future[ProviderResponse].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
provider |
AnthropicProvider |
|
request |
ProviderRequest |
|
onEvent |
StreamCallback |