Documentation
¶
Overview ¶
Package awssig holds the shared AWS SigV4 signing and Bedrock Mantle routing helpers used by both the anthropic-go and openai-go interceptors. It depends only on stdlib and the AWS SDK so it can be imported from either SDK-specific interceptor package without pulling in the other SDK.
Index ¶
Constants ¶
const PRMUserAgent = "sdk-ua-app-id/APN_1.1%2Fpc_cdfmjwn8i6u8l9fwz8h82e4w3%24"
PRMUserAgent is Coder's AWS Partner Revenue Measurement (PRM) attribution marker for outbound Bedrock requests. It is appended to the User-Agent header so AWS can recognize the traffic as Coder-associated Bedrock usage.
It is Bedrock-specific: only the Bedrock option builders apply it. Other AWS-signed endpoints must not send it without their own attribution agreement.
const ServiceBedrockMantle = "bedrock-mantle"
ServiceBedrockMantle is the AWS SigV4 service name for Bedrock Mantle.
Variables ¶
This section is empty.
Functions ¶
func AppendPRMUserAgent ¶
AppendPRMUserAgent appends the Coder PRM attribution marker to the request's User-Agent header.
func BaseURLForModel ¶
BaseURLForModel resolves the upstream Mantle base URL for a given model. It parses rawBase, trims any existing vendor path segment, then re-appends the one the model requires: "anthropic." models use /anthropic, "openai." models use /openai/v1, and anything else (third-party) uses /v1 so the SDK's /chat/completions route hits the root /v1/chat/completions endpoint.
func BearerMiddleware ¶
func BearerMiddleware(token string) func(req *http.Request, next func(*http.Request) (*http.Response, error)) (*http.Response, error)
BearerMiddleware authenticates a request with a user-supplied AWS Bedrock API key instead of SigV4. Callers install it in place of SignMiddleware so no deployment AWS credentials are resolved for the request.
func SignMiddleware ¶
func SignMiddleware(creds aws.CredentialsProvider, region, service string) func(req *http.Request, next func(*http.Request) (*http.Response, error)) (*http.Response, error)
SignMiddleware returns an stdlib HTTP middleware that SigV4-signs the request for the named AWS service. It reads and restores the body for hashing, then signs with the given credentials and region. Callers wrap it in their SDK-specific option.WithMiddleware adapter.
The caller is responsible for service-specific headers and user-agent attribution.
Types ¶
type MantleConfig ¶
type MantleConfig struct {
BaseURL string
Region string
Creds aws.CredentialsProvider
}
MantleConfig carries only what the OpenAI-shaped interceptors need to reach Bedrock Mantle: the signing region and credentials, and the base URL that BaseURLForModel rewrites per model. It deliberately excludes the InvokeModel fields (Model, SmallFastModel, Protocol) that those interceptors never use; the messages interceptor keeps the full messages.BedrockRuntime for those.