Skip to content

Conversation

@PederHP
Copy link
Contributor

@PederHP PederHP commented Dec 14, 2025

For agentic loops the cost difference between caching and not caching is massive, and it's really awkward to use caching with the extensions. And not really possible at all at the system-level (because of how it converts without using the raw representation factory). Using raw representation factory also means one has to re-implement the mapping from MEAI to Anthropic content types. Instead this PR adds a new extension method that uses AdditionalProperties to store the CacheControl and then uses it while mapping in the existing extension code.

@PederHP PederHP requested a review from a team as a code owner December 14, 2025 11:52
@PederHP PederHP force-pushed the feature/meai-cache-control-extension branch 3 times, most recently from b38ea33 to 6a6e29c Compare December 14, 2025 12:49
@PederHP
Copy link
Contributor Author

PederHP commented Dec 14, 2025

Let me know if you want a separate extension for beta and non-beta cache control (currently the outer one is shared). I also added a new file. I can fold it into the extensions file, but it's getting massive, so I think if it's not ok to have more than one top-level MEAI related file - then maybe there should be a folder? Otherwise the file is just going to keep growing and get more and more unwieldy.

@stainless-app stainless-app bot force-pushed the next branch 2 times, most recently from a6ccfa7 to 007b0c0 Compare December 18, 2025 22:39
@PederHP PederHP force-pushed the feature/meai-cache-control-extension branch from 6a6e29c to f88b66b Compare December 19, 2025 19:44
@PederHP PederHP force-pushed the feature/meai-cache-control-extension branch from ae28dee to edc3cfb Compare January 26, 2026 18:17
stainless-app bot and others added 24 commits January 29, 2026 17:01
* fix: use Properties initializer for InputSchema in IChatClient extensions (anthropics#83)

* chore(ci): Add Claude Code GitHub Workflow (#273)

* "Claude PR Assistant workflow"

* "Claude Code Review workflow"

* fix: use Properties initializer for InputSchema in IChatClient extensions

The InputSchema constructor was being passed properties as rawData,
which caused them to be serialized at the top level of the JSON object
instead of under a "properties" key. This resulted in invalid JSON Schema
that failed Anthropic API validation with error:
"tools.0.custom.input_schema: JSON schema is invalid"

The fix uses property initializer syntax to correctly populate the
Properties property, ensuring the schema is valid JSON Schema draft 2020-12.

Also updates tests to expect the corrected schema format.

Fixes anthropics#82

* Remove added workflows

---------

Co-authored-by: dtmeadows <dmeadows@stainless.com>

* Add MEAI User-Agent for IChatClient implementation

* Fix failing UT for new schema properties pattern

* Add MEAI user agent + UT for betaservice

* Address PR comments

* Use FrozenDictionary for MEAI headers and fix User-Agent test assertions

* Add missing System.Linq using for ToArray extension method

* Fix User-Agent tests to verify single header with multiple values

* Fix lint issues: use collection expressions and simplify regex

---------

Co-authored-by: Matt Brailsford <me@mattbrailsford.com>
Co-authored-by: dtmeadows <dmeadows@stainless.com>
Co-authored-by: Claude Code (/Users/davidmeadows/stainless/stainless) <noreply@anthropic.com>
* SSE implementation

* Add aws cred store

* Adapt AWS authentication

* Fix Streaming for bedrock

* Add nuget stubs

* Lint files

* Update code comments

* Add support for netstandard to bedrock
Removed Async streaming implementation

* Format code

* Cleanup code

* make mr linter happy

* Fix net9 specific optimizations

* Apply review comments

* Fix linting issues

* applied review comments

* Remove argument check

* Remove unused code

* Adapt method header NetStandard switch

* lint code

* Fix merge conflicts from source

* Apply review comments

* Removed unused method

* Apply code review changes

* Add bedrock example

* rename event stream helper

* linting

* remove incorrectly added example project

* fix build

* Fix tests

* fix build and lint

* apply review comments

* revert merge conflict issue

* lint

* Split examples into multiple projects for bedrock, anthropic and foundry

* apply review comments

* Remove bedrock from general testing loop as currently unsupported by test tool

* Update Examples

* lint

* Cleanup examples

* update comment

* update exception

* Update src/Anthropic.Bedrock/LocalShims.cs

* combine if statements

* fix lint?

---------

Co-authored-by: Stephen <stephen@stainless.com>
output_format is depracated in favour of output_config.format. Update api call configuration to reflect this change
update test to reflect this change
* chore: add release notes

* Implement message Aggregator

* Add prism log to gitignore

* Fix test script

* Add streaming aggregators

* Refactored aggregator for v0.1.0

* Fixed copypaste SignatureDelta issue

* WIP Aggregator refactor

* applied review comments

* Fix merge conflict
Format code

* apply review comments

* Lint code

* Apply code review

* fix test results

* apply review comments

* properly await Aggregate function

* lint files

* Refactor code to provide in-place aggregation

* Add example

* Fix examples and lint code

* Update readme and example

* Fix tests

* apply review sugestions

* fix tests

* fix tests

* Apply suggestions from code review

Co-authored-by: Stephen <stephen@stainless.com>

* typo

* remove obsolete gitignore entry

* typo

* lint

* fix linter?

* fix lint

* fixes

* example working

* done?

* fix formatting

* fixes

* add exception when computed timeout is too high

* update readme

* address feedback

* formatting

---------

Co-authored-by: meorphis <eric@stainless.com>
Co-authored-by: JPVenson <github@jpb.email>
Co-authored-by: JPVenson <ger-delta-07@hotmail.de>
* Add vertex provider
Add vertex example

Add explicit body check for vertex

Readd explicit check for model value in bedrock client

lint

reintroduce null forgiving operator as required by build

* apply review suggestions

* Update examples/MessagesExample.Vertex/Program.cs

* Apply suggestion from @sd-st

---------

Co-authored-by: Stephen <stephen@stainless.com>
Add handling for nullable union types (e.g., "type": ["integer", "null"])
generated by the C# MCP SDK for optional nullable parameters. Transforms
them to simple types for non-required properties since structured outputs
doesn't support union types.

Changes:
- Add nullable union type normalization in schema transform
- Add TransformNullableUnionType helper for tool property processing
- Reorder required/properties parsing to support transformation
- Add tests for nullable union type transformation
Add AIContentCacheExtensions with WithCacheControl() methods that allow
setting Anthropic prompt caching on AIContent instances via
AdditionalProperties.

Changes:
- New AIContentCacheExtensions.cs with WithCacheControl(CacheControlEphemeral)
  and WithCacheControl(TTL) extension methods
- Update CreateMessageParams in both AnthropicClientExtensions and
  AnthropicBetaClientExtensions to apply cache control when mapping AIContent
  to Anthropic content block params (TextBlockParam, ImageBlockParam,
  DocumentBlockParam, ToolUseBlockParam, ToolResultBlockParam)
- Fix system message handling in both clients to support cache control
- Add unit tests for extension methods and request serialization

The Beta client converts from CacheControlEphemeral to BetaCacheControlEphemeral
internally, so users can use the same extension methods with both clients.
@PederHP PederHP force-pushed the feature/meai-cache-control-extension branch from 6892ce7 to 413a2b2 Compare February 7, 2026 12:34
@stainless-app stainless-app bot force-pushed the next branch 5 times, most recently from 2402c71 to 9ae6014 Compare February 9, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants