feat: forward engine routing (incl. namespace pools) via ClientOptions.environment (ENG-2612) - #67
Merged
Conversation
…(ENG-2612)
Add an optional `environment` mapping to ClientOptions and send it verbatim
as the `environment` field of the session request when set. This lets a
caller pin a session to a specific engine pod / devspace / preview
(e.g. {"podName": ..., "engineVersion": ...}) — the same routing the Lab
page and the e2e-tests browser adapter already use by injecting an
`environment` object into the session-token body.
Needed by anam-org/e2e-tests release qualification: its python_sdk adapter
sets ANAM_POD_NAME/ANAM_ENGINE_VERSION to target the freshly deployed
release pod and passes them via ClientOptions(environment=...), which the
SDK previously had no way to forward. Omitted entirely for production.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
bnogas
approved these changes
Aug 5, 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
Add an optional
environmentmapping toClientOptionsand send it verbatim as theenvironmentfield of the session request body when set. This lets a caller steer a session to a non-default engine target — most importantly a namespace pool — e.g.:Why namespace routing (the primary use case)
The backend accepts three targeting keys with precedence
namespace>podName>engineVersion(anam-lab session route →X-Anam-Target-Namespace/X-Anam-Target-Pod/X-Anam-Engine-Version):namespacetargets an engine namespace pool (anam-engine-preview-<n>ordevspace-<name>). The coordinator fans each session out to any ready worker in that namespace, so it scales with the number of engine replicas and survives a pod restart mid-run.podNamesingle-hops to one exact pod with no fan-out — a single replica serves one session, so a 2nd concurrent session gets503 "No personas available".release-e2e(ENG-2612) deploys the engine intodevspace-release-e2eand routes by namespace for exactly this reason. This PR is what lets the python SDK carry that key — it previously had no way to, so the harness raisedRuntimeError: ClientOptions.environment is required for ANAM_* routing overrides.This is not a new routing capability — the backend already honours the
environmentobject; the browser/JS path injects it into the session-token request today. This PR gives the direct API-key path a first-class, routing-key-agnostic way to send the same field.Changes
ClientOptions.environment: dict[str, str] | None = None(documented;namespace/podName/engineVersion).CoreApiClient.start_sessionaddsbody["environment"]only when set — omitted entirely for production, so no behaviour change for existing callers.environmentwhen set and omits it when unset.Because the dict is forwarded verbatim, no key-specific code is needed —
namespace,podName, andengineVersionall pass through unchanged (verified against the directPOST /v1/engine/sessionschema, which acceptsenvironment.namespace).Validation
pytest -q— 63 passedruff check/ruff format --check— cleanmypy src/anam/_api.py src/anam/types.py— cleanFollow-up
After this merges + is tagged, bump the
python-sdkpin inanam-org/e2e-tests(currentlyv0.5.0-alpha.2) so the release-e2epython_sdk/passthroughscenarios route to the deployed namespace pool.🤖 Generated with Claude Code