Open
Conversation
Introduce ModerationParams, ModerationResult, and ModerationResponse to support content moderation via the gateway provider. Add ModerationProvider as an optional interface and a Moderation bool on Capabilities so callers can discover support at runtime.
UnsupportedError distinguishes 'provider does not support this operation' (e.g. moderation on Anthropic) from the existing UnsupportedProviderError (provider not registered at all). Carries the operation name so callers can branch on what was refused.
Match the existing re-export pattern so callers can use anyllm.ModerationParams, anyllm.ErrUnsupported, etc. without importing the providers and errors subpackages directly.
Call POST /v1/moderations directly via the captured HTTP client so the include_raw query parameter and gateway-specific 'does not support moderation' 400 mapping to *errors.UnsupportedError are both under our control instead of the openai-go SDK's. Capture baseURL, httpClient and platform token on Provider so direct HTTP calls honour the same auth the embedded SDK uses, and advertise Moderation in Capabilities.
Cover the happy path, include_raw query parameter, the two unsupported phrasings that map to *UnsupportedError, status-code-to-error mapping for 401/402/429/502/504, platform and non-platform auth on the direct HTTP call, and an env-gated integration test.
Show the gateway provider's Moderation method and how to branch on UnsupportedError when the backend model has no moderation support.
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 content moderation support to the Go SDK's gateway provider, exposing the gateway's
POST /v1/moderationsendpoint through a newModerationProviderinterface. Introduces*errors.UnsupportedErrorso callers can cleanly detect backends (e.g. Anthropic) that do not offer moderation.Changes
ModerationParams,ModerationResult,ModerationResponse,ContentPart,ImageURLand the optionalModerationProviderinterface inproviders/types.go; addModeration booltoproviders.Capabilities.UnsupportedError,ErrUnsupportedsentinel,CodeUnsupportedconstant, andNewUnsupportedErrorconstructor inerrors/errors.goto distinguish "provider does not support this operation" from the existing "provider not registered" case.anyllmpackage to match the existing alias pattern.Moderationon*gateway.Providerby callingPOST /v1/moderationsdirectly with the captured*http.Client, soIncludeRawcan be forwarded as?include_raw=trueand the gateway's locked"does not support moderation"/"multimodal moderation"400 phrasing can be mapped to*UnsupportedError. CapturebaseURL,httpClientand the platform token onProviderat construction so direct HTTP calls share the same auth as the embedded openai-go SDK. AdvertiseModeration: trueincapabilities()and add theproviders.ModerationProviderinterface assertion.httptest-based tests covering the happy path, theinclude_rawquery parameter, both unsupported phrasings (moderation / multimodal) mapping to*UnsupportedError, status-code mapping for 401/402/429/502/504, platform and non-platform auth on the direct HTTP call, and an env-gated integration test.Moderationmethod and how to branch onUnsupportedError.Testing
go test ./errors ./providers/gateway -race -count=1(targeted to packages changed)TestIntegrationModerationis env-gated onGATEWAY_API_BASE/GATEWAY_PLATFORM_TOKENand skips when unset.Checklist
make lint)make test)