Universal.Operative.Sdk.Discrete.Microsoft.Foundry
2.0.0
dotnet add package Universal.Operative.Sdk.Discrete.Microsoft.Foundry --version 2.0.0
NuGet\Install-Package Universal.Operative.Sdk.Discrete.Microsoft.Foundry -Version 2.0.0
<PackageReference Include="Universal.Operative.Sdk.Discrete.Microsoft.Foundry" Version="2.0.0" />
<PackageVersion Include="Universal.Operative.Sdk.Discrete.Microsoft.Foundry" Version="2.0.0" />
<PackageReference Include="Universal.Operative.Sdk.Discrete.Microsoft.Foundry" />
paket add Universal.Operative.Sdk.Discrete.Microsoft.Foundry --version 2.0.0
#r "nuget: Universal.Operative.Sdk.Discrete.Microsoft.Foundry, 2.0.0"
#:package Universal.Operative.Sdk.Discrete.Microsoft.Foundry@2.0.0
#addin nuget:?package=Universal.Operative.Sdk.Discrete.Microsoft.Foundry&version=2.0.0
#tool nuget:?package=Universal.Operative.Sdk.Discrete.Microsoft.Foundry&version=2.0.0
Universal.Operative.Sdk.Discrete.Microsoft.Foundry
Documents and failures
OpenAIResponses maps DocumentBlock to native input_file content for base64 data, public URLs, and OpenAI file IDs, including document-only messages. Inline data uses the source media type and Title as the filename (default document.pdf). TextSource documents become input_text. Unsupported source kinds and file IDs explicitly issued by other providers throw NotSupportedException. File availability, supported formats, size limits, and model document capabilities remain provider constraints.
OpenAIChat, MaiChat, and AnthropicMessages reject documents before sending. Documents nested in tool-result content are unsupported for every shape. Malformed provider tool-argument JSON throws JsonException with call ID, tool name and original arguments in Data; no empty-object recovery or automatic payload logging occurs.
Audio, video, unknown blocks and raw JSON blocks are unsupported and throw before a request is sent. Tool results support text for every shape, and images for AnthropicMessages; other tool-result content throws instead of being discarded.
Refusal explanations are preserved as ordinary text, including inside tool results. Provider-owned server-tool calls and results are omitted only when they occur directly in archived assistant messages before the latest user or tool input. This permits cross-provider history without claiming native server-tool continuation support. Such blocks in the current assistant tail or prefill, user/system input, or nested tool results throw NotSupportedException before sending. Without a later user or tool input, an assistant message is not considered archived.
HTTP failures propagate Universal.Microsoft.Foundry.Client.FoundryException unchanged: use StatusCode (for example, HTTP 429), ResponseBody, and RequestId. Provider-reported failures in HTTP-success bodies or streaming events throw FoundryResponseException, exposing ErrorCode, ErrorType, and an independent Payload copy. These fields are provider-supplied and may be absent. Unexpected stream termination remains a protocol failure (InvalidOperationException). Applications choose fallback and retry policy; they need not parse exception messages to identify provider-reported rate-limit codes or HTTP status codes.
Quick start
dotnet add package Universal.Operative.Sdk.Discrete.Microsoft.Foundry
using Universal.Microsoft.Foundry.Client;
using Universal.Operative.Sdk.Discrete;
using Universal.Operative.Sdk.Discrete.Microsoft.Foundry;
string apiKey = Environment.GetEnvironmentVariable("FOUNDRY_API_KEY") ?? throw new InvalidOperationException("Set FOUNDRY_API_KEY.");
using FoundryClient client = new FoundryClient("https://my-resource.services.ai.azure.com", apiKey);
using IModel model = new FoundryModel(client, FoundryModel.ApiShape.OpenAIResponses, new FoundryModel.Options { ModelId = "my-deployment", MaxOutputTokens = 1024 });
Choose OpenAIChat, OpenAIResponses, AnthropicMessages, or MaiChat for the deployment's API. Set the model ID to its Foundry deployment name.
Construct models with the typed Options object; the former constructor taking a model ID, output-token limit and streaming flag has been removed. The injected FoundryClient remains owned by its caller.
OpenAI function strictness
For OpenAIChat and OpenAIResponses, the adapter forwards a boolean ToolDefinition.Extensions["openai"]["strict"] to each function definition in both buffered and streaming requests. Explicit false remains "strict": false; explicit true remains "strict": true. An absent or null setting omits the wire field and leaves provider defaults in effect.
Chat Completions places it at tools[].function.strict; Responses places it at tools[].strict. The adapter forwards the supplied parameter schema without changing required, adding nullable alternatives, or closing objects. In particular, disabling strictness preserves optional properties. When enabling strictness, the caller supplies a compatible schema. The OpenAI hint does not change Anthropic or MAI tool definitions.
The adapter forwards each tool definition's explicit strictness hint without changing its schema.
Prompt caching
Azure OpenAI's provider caching remains automatic by default. Eligible requests need a repeated prompt prefix of at least 1,024 tokens. FoundryModel does not cache responses. Cache usage is reported in Message.Usage.Extensions when the provider returns it:
foundry.cached_tokens: Azure OpenAI cached input tokens.foundry.cache_write_tokens: Azure OpenAI cache writes, when reported by the deployment.- For Claude, the same
anthropicextension as the direct Anthropic adapter holdscacheReadInputTokensandcacheCreationInputTokens. Claude'sUsage.InputTokensis the uncached portion; useusage.GetTotalInputTokens()to include cache reads and writes. UseFoundryUsageExtensions.ProjectCompactionTokensas a compaction transformer's projected-token calculator.
The following Azure OpenAI controls are optional. Leave them unset to keep the provider default. Select a cache key based on prompts that share a stable prefix; a per-session key can help multi-turn affinity but may reduce reuse across sessions. Hash sensitive identifiers before sending them. PromptCacheRetention applies to supported older models; PromptCacheOptions, PromptCacheSystemBreakpoint, and PromptCacheBreakpointSelector are for deployments supporting explicit breakpoints (GPT-5.6 and later Standard deployments). The selector can mark a stable text or image block in a message. Set PromptCacheOptions to { "mode": "explicit" } to avoid the implicit latest-message cache write on GPT-5.6 and later; then mark at least one reusable prefix of 1,024 tokens or more. Unsupported controls may cause the provider to reject a request.
using FoundryModel model = new FoundryModel(client, FoundryModel.ApiShape.OpenAIResponses, new FoundryModel.Options { ModelId = "my-deployment", PromptCacheKeySelector = conversation => GetStableHashedCacheKey(conversation), // PromptCacheSystemBreakpoint = true,
// PromptCacheOptions = JsonSerializer.SerializeToElement(new { mode = "explicit" }),
});
Claude's Foundry Messages shape follows the direct Anthropic adapter: it marks the tools, system prompt and latest message with five-minute ephemeral cache breakpoints by default. Set UsePromptCaching = false to omit these markers, or AnthropicPromptCacheTtl = "1h" if the longer, more expensive cache is appropriate.
License
Free for noncommercial use under the Universal.Operative Noncommercial License. Source is closed; commercial use requires a separate license from Andrew Ong.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
-
net10.0
- Universal.Microsoft.Foundry.Client (>= 1.1.0)
- Universal.Operative.Sdk.Discrete (>= 4.0.0)
-
net11.0
- Universal.Microsoft.Foundry.Client (>= 1.1.0)
- Universal.Operative.Sdk.Discrete (>= 4.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Targets .NET 10 and .NET 11; removes .NET 8 support. Use typed FoundryModel.Options. Unsupported content fails before transport. Omits provider-owned server tools only in archived assistant history before later user/tool input; rejects current or nested unsupported server-tool content. Refusal explanations remain text.