X‑UPSTREAM‑ENV for HCP Gateway
The required header that routes your call on the public HCP endpoint to the right CCG environment (dev/stage/test) — omitting or mis-setting it causes a 404.
Quick Reference
- Header-based environment routing for HCP (Health Care Platform) APIs
X‑Upstream‑Envis a required, validated custom header used by the HCP Gateway to route a single public endpoint to multiple internal environments (e.g.,dev,stage,test).- Clients must send a permitted value (typically
dev,stage, ortest) or requests may default or fail with404 NOT_FOUND. Ensure every proxy in front of HCP preserves this header. - Scope
- Applies to: Any service calling HCP‑exposed endpoints.
- Does not cover: Non‑HCP gateways with different routing semantics.
X-UPSTREAM-ENV is a custom HTTP header commonly used in API ecosystems to indicate the target environment for an upstream service call. It helps route requests to the correct backend environment without changing the base URL.
Why use it?
- Environment Routing: Avoids hardcoding multiple URLs for different environments.
- Consistency: Same API endpoint can serve multiple environments based on header.
- Flexibility: Useful in microservices and API gateway setups where routing logic depends on headers.
Contract
Header name & casing
- Canonical name:
X-Upstream-Env - HTTP is case-insensitive, but normalize to this exact form for consistency in docs, logs, and matchers.
Allowed values and requirement level
See X-Upstream-Env — Values & Error Reference for the full allow-list and requirement level by environment.
Interaction with Hostnames
- Hostnames like
api-stg.uhg.com(non‑prod) are not sufficient to determine the final target; the header selects the upstream environment behind the gateway (e.g., route stg host +devheader to DEV backends).
Client Usage
cURL
# Payment Methods search (non-prod)
curl --location --request POST \
'https://api-stg.uhg.com/api/financial/commerce/nonprodcheckout/v1/payment-methods/search' \
--header 'X-Upstream-Env: dev' \
--header 'X-Merchant-Id: <merchant-id>' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
"customer": { "name": "Testing", "email": "Jo@test.com" }
}'
info
This pattern (host points to stg, header points to dev) is used across Checkout and Session flows.
Server‑side Behavior (HCP Gateway)
- Header inspection: HCP reads
X‑Upstream‑Envearly in request processing. - Routing decision: The value selects the upstream cluster/partition (DEV, STAGE, PROD).
- Policy enforcement: If invalid/unsupported, HCP will reject with
404 NOT_FOUND. - Auth is separate: JWT/OAuth validation is orthogonal; a valid token + invalid env will still fail.
Full error-handling reference
See X-Upstream-Env — Values & Error Reference for the validation table, sample error payloads, and FAQ.
Security Notes
- Header ≠ authorization. Route selection is not a permission boundary; always require valid OAuth/JWT scopes.
- Least privilege: Tokens scoped to the chosen environment.
- Audit & logging: Log the header value alongside request IDs to diagnose cross‑env issues.