Table of Contents

Class AnthropicService

Namespace
Mythosia.AI.Services.Anthropic
Assembly
Mythosia.AI.dll
public class AnthropicService : AIService, IAIService, IAIRunService, IAIRequestFeatureService, IFunctionRegisterable, IAIProcessingInfoService
Inheritance
AnthropicService
Implements
Inherited Members
Extension Methods

Constructors

AnthropicService(string, HttpClient)

public AnthropicService(string apiKey, HttpClient httpClient)

Parameters

apiKey string
httpClient HttpClient

AnthropicService(string, string, HttpClient)

Creates a AnthropicService with a specific model.

public AnthropicService(string apiKey, string model, HttpClient httpClient)

Parameters

apiKey string
model string
httpClient HttpClient

Properties

AdaptiveThinkingDisplay

Controls whether adaptive-thinking models return readable summarized reasoning. This value is sent only when adaptive thinking is explicitly enabled.

public ClaudeThinkingDisplay AdaptiveThinkingDisplay { get; set; }

Property Value

ClaudeThinkingDisplay

AdaptiveThinkingEffort

Selects the low/medium/high/xhigh/max effort range on adaptive-thinking Claude models. XHigh is rejected for Opus 4.6 and Sonnet 4.6 because those models do not support it. Auto preserves the legacy ThinkingBudget mapping using effort levels the selected model supports. Opus 5.5 uses medium for its default/explicit adaptive Auto; a positive legacy budget still maps to high/xhigh/max rather than a wire token budget.

public ClaudeReasoningEffort AdaptiveThinkingEffort { get; set; }

Property Value

ClaudeReasoningEffort

HasPendingRunContinuation

Whether the transport will continue this run without a new user request.

protected override bool HasPendingRunContinuation { get; }

Property Value

bool

LastInputTransformations

Input transformations reported across the latest logical request's responses, including streaming fallbacks.

public IReadOnlyList<ClaudeInputTransformation> LastInputTransformations { get; }

Property Value

IReadOnlyList<ClaudeInputTransformation>

LastThinkingContent

Contains the thinking/reasoning content from the last non-streaming API call. Populated when the response contains a thinking block. This can occur even when ThinkingBudget is disabled for models whose adaptive thinking is always on.

public string? LastThinkingContent { get; }

Property Value

string

Provider

The AI provider for this service

public override string Provider { get; }

Property Value

string

SupportsExtendedThinking

Returns true if the current model supports a Claude thinking mode. Despite this legacy property name, a true value can mean either manual extended thinking (thinking.type=enabled) or adaptive thinking (thinking.type=adaptive). Claude Fable 5, Mythos 5, Opus 5, Sonnet 5, and Opus 4.7+ are adaptive-only and do not accept budget_tokens.

public bool SupportsExtendedThinking { get; }

Property Value

bool

ThinkingBudget

Controls the thinking token budget for Claude extended thinking. -1 requests disabled thinking where the model permits it. Fable 5 and Mythos 5 cannot disable thinking, so this setting uses their lowest effort and omits the readable summary instead. 1024+ is an exact token budget on manual-thinking models. On adaptive-thinking models, it retains the legacy high/xhigh/max effort mapping unless AdaptiveThinkingEffort is set explicitly. Sonnet 5.5 uses adaptive/high when this property is untouched; explicitly disabling it selects between_tools, which retains progress updates between tools. Supported models: Claude Fable 5, Claude Mythos 5, Claude Sonnet 5.5 / 5 / 4+, Claude Opus 5 / 4+, and Claude Haiku 4.5+. Note: adaptive-thinking models omit temperature; legacy manual-thinking models force it to 1.

public int ThinkingBudget { get; set; }

Property Value

int

ThinkingMode

Selects the thinking phase on Sonnet 5.5. Auto preserves its adaptive/high default unless thinking was explicitly disabled. Other models accept Auto only.

public ClaudeThinkingMode ThinkingMode { get; set; }

Property Value

ClaudeThinkingMode

ThinkingPrefixMismatchBehavior

Controls the API's treatment of thinking blocks bound to an edited prefix. Null uses the provider default without opting into the beta.

public ClaudeThinkingPrefixMismatchBehavior? ThinkingPrefixMismatchBehavior { get; set; }

Property Value

ClaudeThinkingPrefixMismatchBehavior?

Methods

ApplyCapabilityRequestProfile(AIRequestProfile)

Applies only execution-local profile settings needed to describe capabilities.

protected override void ApplyCapabilityRequestProfile(AIRequestProfile profile)

Parameters

profile AIRequestProfile

Remarks

Common builder overrides are already captured. Custom providers may override this hook with SetExecutionSetting calls for native mode flags. Do not prepare execution, reserve token budgets, invoke callbacks, validate requests, or modify service/caller-owned state. Execution profile hooks are intentionally not called during inspection.

ApplyProviderSpecificRequestProfile(AIRequestProfile)

protected override Action ApplyProviderSpecificRequestProfile(AIRequestProfile profile)

Parameters

profile AIRequestProfile

Returns

Action

ApplyRequestProfile(AIRequestProfile)

protected override Action ApplyRequestProfile(AIRequestProfile profile)

Parameters

profile AIRequestProfile

Returns

Action

CaptureProviderRequestOptions(Message)

Captures and consumes provider-specific per-request options before execution starts.

protected override object? CaptureProviderRequestOptions(Message message)

Parameters

message Message

Returns

object

Remarks

Framework delegation and tool rounds reuse the returned snapshot; new public calls capture independently. Internal summary and rewrite work do not call this hook and do not inherit these options.

CaptureRequestSettings(IDictionary<string, object?>)

Captures provider and common defaults. Overrides copy native mutable option values.

protected override void CaptureRequestSettings(IDictionary<string, object?> settings)

Parameters

settings IDictionary<string, object>

CloneProviderRequestOptions(object?)

Creates fresh provider execution state when a prepared request is executed again.

protected override object? CloneProviderRequestOptions(object? options)

Parameters

options object

Returns

object

CreateFunctionMessageRequest()

Creates HTTP request with function definitions

protected override HttpRequestMessage CreateFunctionMessageRequest()

Returns

HttpRequestMessage

CreateMessageRequest()

Creates the HTTP request message for the AI service

protected override HttpRequestMessage CreateMessageRequest()

Returns

HttpRequestMessage

CreateMessageWithImageUrl(string, string)

Downloads an image from URL and converts to base64 for Claude

public Task<Message> CreateMessageWithImageUrl(string prompt, string imageUrl)

Parameters

prompt string
imageUrl string

Returns

Task<Message>

ExtractFunctionCalls(string)

Extracts every function call from one API response.

protected override (string content, FunctionCallBatch functionCalls) ExtractFunctionCalls(string response)

Parameters

response string

Returns

(string content, FunctionCallBatch functionCalls)

ExtractResponseContent(string)

Extracts the response content from the API response

protected override string ExtractResponseContent(string responseContent)

Parameters

responseContent string

Returns

string

GetCompletionAsync(Message)

public override Task<string> GetCompletionAsync(Message message)

Parameters

message Message

Returns

Task<string>

GetCompletionWithImageAsync(string, string, CancellationToken)

public override Task<string> GetCompletionWithImageAsync(string prompt, string imagePath, CancellationToken cancellationToken = default)

Parameters

prompt string
imagePath string
cancellationToken CancellationToken

Returns

Task<string>

GetConversationCompactionBlockReason()

Returns a reason when protocol state requires retaining the original conversation prefix.

protected override string? GetConversationCompactionBlockReason()

Returns

string

GetInputTokenCountAsync()

Gets the token count for the current conversation

public override Task<uint> GetInputTokenCountAsync()

Returns

Task<uint>

GetInputTokenCountAsync(string)

Gets the token count for a specific prompt

public override Task<uint> GetInputTokenCountAsync(string prompt)

Parameters

prompt string

Returns

Task<uint>

GetModelMaxOutputTokens()

Returns the maximum output tokens allowed for the current model. Override in each service to provide model-specific limits.

protected override uint GetModelMaxOutputTokens()

Returns

uint

ResolveRequestCapabilities()

Resolves adapter support using RequestSetting and CurrentRequestFeatures without side effects.

protected override AIModelCapabilities ResolveRequestCapabilities()

Returns

AIModelCapabilities

Remarks

Custom providers may override this hook. The default preserves compatibility by returning Unknown. Overrides must not send requests, consume options, change history or invoke user callbacks.

ResolveSpeedSupport(InferenceSpeed)

Locally resolves processing-mode support without checking account entitlement or live capacity.

protected override CapabilitySupport ResolveSpeedSupport(InferenceSpeed speed)

Parameters

speed InferenceSpeed

Returns

CapabilitySupport

StreamCompletionAsync(Message, Func<string, Task>)

public override Task StreamCompletionAsync(Message message, Func<string, Task> messageReceivedAsync)

Parameters

message Message
messageReceivedAsync Func<string, Task>

Returns

Task

StreamParseJson(string)

Parses streaming JSON data

protected override string StreamParseJson(string jsonData)

Parameters

jsonData string

Returns

string

StreamRoundAsync(StreamOptions, bool, FunctionCallingPolicy, CancellationToken)

Executes a single streaming round: sends an HTTP request, reads the SSE stream, yields chunks, and handles function execution if detected. Yield a FunctionResult to signal the template to continue to the next round. Pending native asynchronous calls also keep the round loop active until their results have been delivered and the model finishes.

protected override IAsyncEnumerable<StreamingContent> StreamRoundAsync(StreamOptions options, bool useFunctions, FunctionCallingPolicy policy, CancellationToken cancellationToken)

Parameters

options StreamOptions
useFunctions bool
policy FunctionCallingPolicy
cancellationToken CancellationToken

Returns

IAsyncEnumerable<StreamingContent>

ValidateProviderRequestOptions(object?, Message)

Validates captured native options against the completed request before history or HTTP changes.

protected override void ValidateProviderRequestOptions(object? options, Message message)

Parameters

options object
message Message

ValidateRequestFeatures(AIRequestFeatures)

Reject unsupported features before any network request or history mutation.

protected override void ValidateRequestFeatures(AIRequestFeatures features)

Parameters

features AIRequestFeatures

WithAdaptiveThinkingParameters(ClaudeReasoningEffort, ClaudeThinkingDisplay)

Enables adaptive thinking with an explicit Claude effort and display policy.

public AnthropicService WithAdaptiveThinkingParameters(ClaudeReasoningEffort effort, ClaudeThinkingDisplay display = ClaudeThinkingDisplay.Summarized)

Parameters

effort ClaudeReasoningEffort
display ClaudeThinkingDisplay

Returns

AnthropicService

WithBetweenToolsThinking(ClaudeReasoningEffort)

On Sonnet 5.5, disables up-front reasoning while retaining progress updates between tools. Auto uses high effort; Low, Medium and High are supported. XHigh and Max require adaptive thinking.

public AnthropicService WithBetweenToolsThinking(ClaudeReasoningEffort effort = ClaudeReasoningEffort.Auto)

Parameters

effort ClaudeReasoningEffort

Returns

AnthropicService

WithClaudeParameters(int?)

Sets Claude-specific parameters

public AnthropicService WithClaudeParameters(int? topK = null)

Parameters

topK int?

Returns

AnthropicService

WithConstitutionalAI(bool)

Enables or disables Claude's constitutional AI features

public AnthropicService WithConstitutionalAI(bool enabled = true)

Parameters

enabled bool

Returns

AnthropicService

WithConversationInstruction(string)

Queues a persistent mid-conversation system instruction after the next request's user input.

public AnthropicService WithConversationInstruction(string instruction)

Parameters

instruction string

Returns

AnthropicService

WithTemperaturePreset(TemperaturePreset)

Sets temperature for different use cases

public AnthropicService WithTemperaturePreset(TemperaturePreset preset)

Parameters

preset TemperaturePreset

Returns

AnthropicService

WithThinkingBinding(ClaudeThinkingPrefixMismatchBehavior)

Selects explicit server-side prefix validation or dropping of incompatible thinking blocks.

public AnthropicService WithThinkingBinding(ClaudeThinkingPrefixMismatchBehavior behavior)

Parameters

behavior ClaudeThinkingPrefixMismatchBehavior

Returns

AnthropicService

WithThinkingParameters(int)

Sets Claude thinking through the legacy token-budget API. On manual-thinking models, the budget must be at least 1024 and is sent as budget_tokens; max_tokens is adjusted when necessary and temperature is forced to 1. On adaptive-only models, the numeric budget is retained for compatibility and mapped to high/xhigh/max effort instead of being sent to Anthropic.

public AnthropicService WithThinkingParameters(int budgetTokens)

Parameters

budgetTokens int

Returns

AnthropicService

WithTurnInstruction(string)

Queues a system-authority instruction for the next logical request, repeated after its client-tool results.

public AnthropicService WithTurnInstruction(string instruction)

Parameters

instruction string

Returns

AnthropicService

Remarks

The instruction clears at the next user message on the wire. Cleared messages remain in history verbatim.