Repository navigation
feat(providers): native IBM watsonx.ai provider - #1349
Merged
vgmartinez merged 4 commits intoNov 15, 2026
Merged
Conversation
Adds a watsonx provider so watsonx.ai traffic can sit behind TrustGate without IBM's model gateway. - Registry auth is an IBM Cloud API key. The client exchanges it for an IAM bearer token, caches it per key (SHA-256), refreshes at 80% of its lifetime, shares one exchange across concurrent callers, keeps serving a still-valid token through a transient IAM outage, and retries a call once with a fresh token when watsonx answers 401. - provider_options: region (us-south, eu-de, eu-gb, jp-tok, au-syd, ca-tor), project_id (UUID, always taken from the registry, never the request body), api_version (default 2025-10-01), optional base_url for private endpoints. - The gateway encodes OpenAI Chat Completions for watsonx; the client translates to /ml/v1/text/chat and /ml/v1/text/chat_stream: model_id, project_id, tool_choice modes to tool_choice_option, max_completion_tokens to max_tokens, text-only system/assistant/tool content, function tools only, unknown fields dropped. Responses, stream chunks, tool-call arguments, finish reasons and errors come back OpenAI-shaped; streams get a [DONE] and a watsonx error event becomes an in-band error chunk. - Model list: the region's foundation_model_specs (text_chat, withdrawn models skipped, deprecated ones labelled). The listing is authoritative per region, borrowing models.dev prices where a model matches; routing treats models.dev's partial watsonx catalog as unable to prove absence. - Pricing: models.dev "watsonx" is synced into the catalog; registry pricing overrides cover contract rates and unpriced models. - Connection test mints an IAM token and lists the region's models. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KF89yDnBWqZ6yB3bLqAtb9
Contributor
Trivy code scan — HIGH/CRITICALNo HIGH or CRITICAL vulnerabilities found. (run) |
…-native-integration-rtssu4 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KF89yDnBWqZ6yB3bLqAtb9
Registering a generic agent now asks its endpoint for a task that does not exist (53a9e19). The fake agent records that call, so the three tests that expect no forwarded call saw one more than expected: TestA2A_RefusesMethodsItDoesNotForward, TestA2A_PolicyBlocksTheMessage and TestA2A_AuthenticatesAndRoutes. forgetRegistrationCheck asserts the registration made exactly that one check (tasks/get on 0.3, GetTask on 1.0), then drops it, so each test counts only what the gateway forwards afterwards. The gateway's behaviour is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KF89yDnBWqZ6yB3bLqAtb9
develop's secret stores check each credential reference against a store's allowed destinations, using a host rule per provider; the watsonx provider predates that and had none, so TestEveryProviderHasAHostRule failed and a store with allowed destinations would have refused every watsonx reference. - pkg/domain/provider owns the watsonx host rules: the regions that serve watsonx.ai, WatsonxHost(region) and WatsonxIAMHost. watsonx honors base_url. The options decoder and the IAM client read them from there instead of keeping their own copy. - secretref sends a watsonx credential to the region's host (or base_url) and to iam.cloud.ibm.com, which receives the API key and returns the bearer token, as GCP and Azure list their token hosts. A region that serves no watsonx.ai leaves no host and fails closed. - TestHonorsBaseURLMatchesTheOptions now covers WatsonxOptions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KF89yDnBWqZ6yB3bLqAtb9
vgmartinez
marked this pull request as ready for review
November 13, 2026 18:06
This was referenced Nov 15, 2026
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.
Summary
Adds
watsonxas a native LLM provider, so IBM watsonx.ai traffic can go through TrustGate directly instead of through IBM's model gateway on IBM Cloud. watsonx's API is not OpenAI-compatible and its IAM tokens expire after about an hour. This provider handles both.Console side: NeuralTrust/app#4855 (same branch name).
What a registry takes
api_keyholding an IBM Cloud API key. Users never paste a bearer token.provider_options:region: required, one ofus-south,eu-de,eu-gb,jp-tok,au-syd,ca-tor. It is an allow-list because the region picks the host the IAM token is sent to.project_id: required, a UUID. It always comes from the registry; aproject_idorspace_idin the request body is dropped, so callers cannot point the stored key at another project.api_version: optionalYYYY-MM-DD, default2025-10-01.base_url: optional override for private endpoints.How it works
watsonx/iam.go)iam.cloud.ibm.com. The token is cached per key, with keys held only as SHA-256 digests.watsonx/translate.go)resolveProviderWireFormat). Policies, guardrails, cross-format callers (Anthropic, Gemini, Responses) and usage accounting therefore work unchanged./ml/v1/text/chatand/ml/v1/text/chat_stream:modelbecomesmodel_id, andproject_idis addedtool_choicenone/auto/requiredbecomestool_choice_option; a named function staystool_choicemax_completion_tokensbecomesmax_tokensindex[DONE]; a watsonxevent: errorbecomes an OpenAI in-band error chunkwatsonx/models.go)foundation_model_specs(text_chat). Withdrawn models are skipped and deprecated ones are labelled.eu-dehas 5 today,us-south7). Prices are borrowed from the catalog where a model matches.providerListingIsNotAuthoritativenow includes watsonx, so routing never treats a model missing from models.dev as absent.watsonxprovider is synced into the catalog. Registrypricing.overrides(for exampleibm/*) cover contract rates and models models.dev does not price.base_url) plusiam.cloud.ibm.com, which receives the API key. This matches how GCP and Azure list their token hosts. The host rules live inpkg/domain/provider(WatsonxHost,WatsonxIAMHost), and the options decoder and IAM client read them from there.Testing
tool_usego test -race ./...: 214 packages ok, 0 failures.go test -tags functional -race -p 1 ./tests/functional/... ./pkg/infra/database/migrations) against Postgres 16 and Redis: 717 passed, 0 failed, 4 skipped. The skips are environmental: noOPENAI_API_KEY, plan rate limiter disabled, needs a real TrustGuard, and RUN-1621.golangci-lint run ./...(v2.14.0): 0 issues.make docswith the pinnedswag: no diff.addlicense -checkandscripts/check-comments.shpass.Not yet verified against live watsonx: no IBM Cloud API key was available. The payload shape follows IBM's
ibm-watsonx-aiSDK, and the regional endpoints were confirmed reachable. Before merging, please run one buffered chat, one streamed chat and one tool call with a real key and project. That is why this PR is a draft.CI: what changed after the first run
The first run failed Lint, OpenAPI Drift and Functional Tests.
develop's own last CI run (88e4288) failed the same three jobs. This branch now:develop(a30823e). That brings in the fixedswitch statusinpkg/app/a2a/translated.go(staticcheck QF1002) and the regenerateddocs/, which clears Lint and OpenAPI Drift.TestA2A_RefusesMethodsItDoesNotForward,TestA2A_PolicyBlocksTheMessageandTestA2A_AuthenticatesAndRouteseach saw one call more than they expected. The newforgetRegistrationCheckasserts the registration made exactly that one check (tasks/geton 0.3,GetTaskon 1.0), then drops it. Gateway behaviour is unchanged.develop's newTestEveryProviderHasAHostRulefailed for watsonx. This one was caused by this PR: without a rule, a secret store with allowed destinations would refuse every watsonx reference. See "Secret stores" above.TestHonorsBaseURLMatchesTheOptionsnow coversWatsonxOptions.Known gaps / follow-ups
space_id)ap-south-1), which runs on AWS with a different IAM🤖 Generated with Claude Code
https://claude.ai/code/session_01KF89yDnBWqZ6yB3bLqAtb9