Repository navigation
Added bedrock client support - #38
Merged
Merged
Conversation
# Conflicts: # .gitignore # CMakeLists.txt # README.md # examples/CMakeLists.txt
The format check of CI (clang-format 18) has been failing on main since ClickHouse#62. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The merge of `main` kept both the new multi-line `COMPONENT_TARGETS` list and the old one-line `set(COMPONENT_TARGETS ...)` from this branch, which dropped `ai-sdk-cpp-langfuse` from the export set and broke CMake configuration. Also set `EXPORT_NAME bedrock` for the Bedrock target, consistently with other components, and format the Bedrock sources with clang-format 18 (as in CI). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nto bedrock-support
- Use the current Claude models on Bedrock (`anthropic.claude-fable-5-2`, `anthropic.claude-opus-5-5`, `anthropic.claude-sonnet-5-5`, `anthropic.claude-haiku-5-5`); `kClaudeFable`, `kClaudeOpus`, `kClaudeSonnet`, `kClaudeHaiku` are aliases for the current generation. - Accept every cross-region inference profile prefix (`global.`, `apac.`, not only two-letter ones) in `InputValidator`: the previous default `kClaudeSonnet4` (`global.anthropic...`) was rejected by the validator. - A stream rejected before sending (validation error, open circuit breaker) now yields the error at once and completes, instead of blocking in `get_next_event` for 60 seconds and then reporting a timeout. - `web_identity_token_file` was unreachable (the `role_arn` branch ran first) and was sent with an empty role ARN; check it first and require `role_arn`. - Remove the vendored AWS SDK header `aws/core/utils/pagination/Paginator.h`: the real SDK ships it, and `install(DIRECTORY include/)` would have installed a copy of an AWS header into the user's include prefix. - Add the `bedrock` component and the `AWSSDK` dependency to the installed package config when built with `AI_SDK_ENABLE_BEDROCK`. - Fix the Bedrock README snippets, which did not compile (`GenerateOptions` is not an aggregate, no `result->text`, no `chunk.text`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tools - Credentials: assumed-role credentials were fetched once at client creation and expired after an hour. `AssumeRole` credentials now come from a provider that refreshes them before they expire (its STS client uses the configured profile or the default chain as the source identity, and the client's region). Web identity credentials use the SDK's `STSAssumeRoleWebIdentityCredentialsProvider` (profile, region, role, session name, token file), which refreshes them itself. - Stream lifetime: the stream held a raw pointer to the client's semaphore, so a stream outliving its `Client` was a use-after-free. The stream now shares ownership of the runtime client and the semaphore. `get_next_event` waits on a condition variable instead of polling every millisecond with a 60 second timeout. `stop_stream` now aborts the HTTP request (`ContinueRequestHandler`) instead of waiting for the whole response. Tool calls are streamed (`contentBlockStart` / `contentBlockDelta` / `contentBlockStop`), and the finish event carries the usage from the `metadata` event; a failed stream finishes with `kFinishReasonError`. - SDK lifecycle: `Aws::InitAPI` is called once per process and the SDK is never shut down. Previously the SDK was shut down when the last client was destroyed and initialized again for the next one (not supported by the SDK), `Aws::ShutdownAPI` also ran from a static destructor, and a failed client construction leaked a reference. - Tools: tool calling via the Converse `toolConfig` (tool specs, tool choice), `toolUse` and `toolResult` content blocks, tool calls parsed from responses, tools executed and multi-step generation via `MultiStepCoordinator`, as in the other providers. Previously tools were silently ignored and tool messages were sent as empty messages. System messages in `messages` are now sent as system content blocks instead of being dropped. - Remove the circuit breaker: it counted validation and access errors, so a few requests with a wrong model ID blocked all requests for 30 seconds, and it did not apply to streaming. Retries are handled by the AWS SDK. - Validation: drop the fixed bounds on `temperature`, `top_p`, and `max_tokens` (and `SecurityConfig::max_tokens_limit`), which contradict some models; the API validates them. `temperature` and `top_p` are not sent to Claude models that reject them (same list as the Anthropic provider, plus Claude Haiku 5), including with an inference profile prefix. - `stream_text` no longer drops the tools and other options when converting `StreamOptions`. - Remove `.kiro/` from `.gitignore` and the "Production-ready" wording. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tials - The Claude constants are now global cross-region inference profile IDs (`global.anthropic.claude-sonnet-5-5`, ...): per the AWS model cards, the current Claude models cannot be invoked on demand with the bare model ID in (almost) any Region. - `ModelDiscovery` uses the same credentials as `BedrockClient` (role, web identity, profile, default chain); the credentials code moved to `bedrock_credentials.cpp`. It no longer applies `endpoint_override`, which is the endpoint of the runtime service, to the control-plane client, and `validate_model_access` accepts inference profile IDs. - When refreshing assumed-role credentials fails, keep using the cached credentials until they actually expire, instead of failing requests while the session is still valid. - `StreamOutlivesClient` restores the AWS environment variables it sets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cache - When `messages` has no non-system turns, send the prompt as the conversation instead of an empty `messages` array, and reject requests with neither a prompt nor a non-system message locally. Merge adjacent turns of the same role (e.g. left after dropping a system message), since Converse requires alternating roles. - Push the finish event and mark the stream complete in one critical section, so a consumer that has read the finish event never sees `has_more_events() == true` and then an empty event after it. - Remove the model list cache and `SecurityConfig::model_cache_ttl`: every `list_available_models` / `validate_model_access` call created a new `ModelDiscovery`, so the cache was never reused. Document that each call queries `ListFoundationModels`, and that `validate_model_access` checks the Region's model list, not access grants. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 062321f. Configure here.
Merging adjacent user turns could put text before `toolResult` blocks, which Claude rejects: the tool results must come first in the user turn that answers the tool calls (text may follow them). The merged turn now keeps all tool results first, then the other blocks in their original order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
alexey-milovidov
added a commit
that referenced
this pull request
Nov 27, 2026
Align the Bedrock client, merged in #38, with the rest of this change: `list_models` returns the foundation model IDs of the Region through `ModelDiscovery`, and `supports_model` is true for every non-empty model ID (inference profiles and ARNs are forwarded to Converse as is). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
alexey-milovidov
added a commit
that referenced
this pull request
Nov 27, 2026
* List models from the provider instead of a static catalog `supported_models` and `supports_model` answered from a hand-maintained list that went stale with every model release, returned false for valid models, and could not know what an API key or a custom `base_url` (OpenRouter, gateways) serves. Requests never consulted it: model names are forwarded to the API as is. - Add `Client::list_models`, which asks the provider's models endpoint (`GET /v1/models`) and follows Anthropic's `has_more`/`last_id` pagination; errors are parsed like completion errors. It uses the same retry policy as other requests (new `HttpRequestHandler::get`). - `supports_model` is now true for every non-empty model name. - `supported_models` stays as the list of well-known names (the `models::k*` constants) and is documented as such. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Bedrock: list models from `ListFoundationModels`, accept any model name Align the Bedrock client, merged in #38, with the rest of this change: `list_models` returns the foundation model IDs of the Region through `ModelDiscovery`, and `supports_model` is true for every non-empty model ID (inference profiles and ARNs are forwarded to Converse as is). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Bedrock: tests for client construction, `supports_model`, `list_models` - Unit tests (no network): a client is created with a region, accepts any non-empty model ID in `supports_model` and rejects "", lists the current Claude models in `supported_models`, and requires a region. - Integration test (skipped without `AI_SDK_IT_BEDROCK`): `list_models` returns the foundation models of the Region. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Fail `list_models` when the pagination cursor repeats A server or gateway that ignores `after_id` and keeps answering `has_more` with the same `last_id` made `list_models` page forever. Report an error when a cursor comes back a second time. Reported by Cursor Bugbot in #68 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Gemini: list models from `GET /v1beta/models` The Gemini provider, merged in #69, answers `list_models` from its own models endpoint: it follows `nextPageToken` (failing if a token repeats), and reports the IDs without the `models/` prefix, the way requests take them. The request and error handling of the OpenAI and Anthropic listing moves to `BaseProviderClient::get_json`, shared by both implementations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

issue: #37
Note : it's v1 tool calling is not supported yet
Note
Medium Risk
Large new optional dependency path with credential/STS handling and AWS SDK lifecycle semantics; mistakes could affect auth or logging safety, but the feature is off by default and isolated behind CMake flags.
Overview
Adds an optional Amazon Bedrock provider behind
AI_SDK_ENABLE_BEDROCK, wiring a newai::bedrockcomponent (ai::bedrock,AI_SDK_HAS_BEDROCK) into CMake install config, the umbrella library, examples, and tests when the AWS SDK for C++ is available.The provider talks to Bedrock through the Converse / ConverseStream APIs (not httplib):
BedrockClientimplements the sharedClientinterface for text generation, streaming, and multi-step tool execution, with request/response mapping, retryable error classification, concurrency limits, and input validation. AWS auth supports the default chain, profiles, VPC endpoint overrides, STS AssumeRole (with refresh), and EKS/OIDC web identity. Model discovery (list_available_models,validate_model_access) uses the Bedrock control plane. Security-focused logging redacts credentials before they hit logs.Documentation and samples are expanded (README Bedrock section,
test_bedrock, component demo, conditionalbasic_chatexample). Unit and opt-in integration tests (AI_SDK_IT_BEDROCK) cover mappers, parsers, streams, validators, and live API behavior. Embeddings on Bedrock still return a not-supported error.Reviewed by Cursor Bugbot for commit bc4a3b2. Bugbot is set up for automated code reviews on this repo. Configure here.