Use a separate environment to validate a deployment without changing production traffic.
Deployment management
Use environments to validate and release deployments with:- Automated tests and evaluations.
- Manual testing in pre-production.
- Performance tests with copies of live requests through shadow traffic.
- Gradual traffic shifts with rolling deployments.
Baseten enables rolling deployments by default for new model environments.
Existing environments keep their promotion settings.
- Dedicated API endpoint. For more information, see Predict endpoints.
- Autoscaling controls: Scale behavior is managed per environment.
- Monitoring and metrics: scope logs and metrics to the environment in the dashboard, or export environment metrics to your own observability stack.
- It can’t be deleted unless the entire model is removed.
- You can’t create additional environments named “production.”
Shadow traffic
Shadow traffic copies a share of an environment’s live HTTP requests to another environment or deployment in the same model, so you can test a deployment on real traffic before you promote it. Clients continue to receive responses from the source deployment, while Baseten discards responses from the target deployment. Shadowing is best effort. Depending on platform and target conditions, Baseten might not copy every sampled request, and copies can fail. Skipped and failed copies don’t affect the client’s response, but the target can receive a smaller share of requests than the percentage you set. The target must meet the source’s regional and compliance constraints. A target environment receives the copies on whichever deployment it’s serving.Shadow traffic is pre-release. The dashboard shows the Traffic routing
section only for workspaces with traffic routing rules enabled, and the
baseten model environment traffic-rule commands may change their arguments,
flags, and output.- UI
- Baseten CLI
- Management API
To start shadow traffic:
- Sign in to your workspace at app.baseten.co and choose Dedicated Inference in the sidebar, then select your model.
- Under Environments, select the source environment.
- In the Traffic routing section, choose Add rule.
- For Target, select the environment or deployment to receive the copies.
- For Traffic to shadow, set the percentage of requests to copy. Shadowing is best effort, so the target can receive a smaller share than configured.
- For Expiration, choose how long the rule runs, up to 7 days.
- For Sampling, choose Random to pick each request independently, or Session-aware to keep a session’s requests together.
- To cancel a copy when the client cancels the original request, select Propagate client cancellation to the target.
- Choose Start shadowing.
- In the source environment’s Traffic routing section, choose Edit.
- Change the percentage, expiration, sampling, or cancellation, then choose Save.
- In the source environment’s Traffic routing section, choose Stop.
- Choose Stop rule to confirm.
x-session-affinity header value, so Baseten copies every
request in a sampled session.
Compare the source’s and target’s logs and metrics
over the same time range. Target metrics include any traffic sent directly to
the target, and the target’s replica-hours bill separately.
A rule also ends when it expires, when a promotion goes into its source or
target environment or promotes its target deployment, or when you deactivate or
delete its source or target. A source environment has one active shadow rule at
a time, so creating another fails until the rule expires or you delete it.
Stopping a rule leaves both deployments running.
For more information, see baseten model environment traffic-rule
and Update an environment’s settings.
Manage environments from the Baseten CLI
Thebaseten model environment commands work on the same environments as the dashboard and the Management API:
baseten model environment list --model-id <model-id>: list a model’s environments.baseten model environment describe --model-id <model-id> --environment production: inspect an environment’s current deployment, autoscaling, and promotion settings.baseten model environment update-autoscalingandupdate-promotion: change an environment’s settings; see schedule autoscaling and rolling deployments.baseten model deployment promote --model-id <model-id> --deployment-id <deployment-id>: promote a deployment into an environment; see Manage deployments.
Custom environments
Each workspace has a configured per-model environment limit. In addition to the standard production environment, you can create custom environments until the model reaches that limit. Create them from the model management page in the Baseten dashboard or through the create environment endpoint in the Management API.Deployment promotion
When you promote a deployment to an environment, Baseten associates the deployment with that environment and applies the environment’s autoscaling settings. If Baseten can reuse the deployment directly, promotion doesn’t create a new deployment ID. Otherwise, Baseten creates a deployment with a unique ID, initializes its resources, and replaces the existing deployment in that environment. A new deployment is created when:- You promote a development deployment.
- The deployment is already associated with another environment.
- The environment has a different instance type or resource profile.
- The deployment moves to a different region.
- The applicable compliance policy differs from the deployment’s current policy.
- Re-deploy on promotion is enabled.
Published deployment promotion
If Baseten can reuse a published deployment, it updates that deployment’s autoscaling settings to match the environment. If promotion creates a new deployment, the source published deployment keeps its existing settings.Direct deployment to an environment
Run the following command from your Truss project to deploy to an existing environment. Replace<environment-name> with its name:
Terminal
Terminal
--create-environment-if-missing, a push to a missing custom environment fails. Production already exists for every model.
--wait confirms deployment readiness. Before sending application traffic, verify that the environment points to the promoted deployment and send a request to its stable endpoint.
The Truss CLI equivalent for an existing environment is truss push --environment <environment-name>.
Only one active promotion per environment is allowed at a time.
Environment access in code
Python Truss models receive the environment through theenvironment keyword argument. Its value is None when the deployment isn’t associated with an environment, so normalize it before reading its name:
model/model.py
load() method to configure per-environment behavior:
model/model.py
load(), you’ll need to enable re-deploy on promotion to ensure the environment is correctly initialized after each promotion. See Re-deploy on promotion for details.
The
environment keyword argument is only available to Python Truss models. Custom servers read the environment name from the filesystem instead. See Environment name.Re-deploy on promotion
By default, promoting a deployment reuses the existing deployment when possible. This is the fastest promotion path, but it meansload() doesn’t re-run. Any environment-specific configuration set during the original load() call persists, even if the deployment moves to a different environment.
You can configure an environment to create a fresh deployment every time you promote to it. For a published source deployment, the new deployment reuses the source image and reruns load() with the target environment’s context, so environment-specific configuration takes effect.
Enable this if your load() method uses kwargs["environment"] to configure per-environment behavior, or if you promote the same source deployment to multiple environments and want each to get a fresh deployment.
To enable re-deploy on promotion:
- Sign in to your workspace at app.baseten.co and choose Dedicated Inference in the sidebar, then select your model.
- Open the environment’s settings.
- Toggle Re-deploy when promoting.
If you promote a deployment that’s already associated with an environment, Baseten creates a new deployment regardless of this setting.
Regional environments
Regional environments constrain replicas to a designated geographic region and provide a dedicated endpoint for region-specific inference routing. Baseten configures the regional restriction for an environment name within a team. See Regional environments for setup, required-endpoint behavior, endpoint formats, and request restrictions. To select a region for an individual deployment instead, see regional deployments.Environment deletion
You can delete environments, except for production. To remove a production deployment, first promote another deployment to production or delete the entire model.- Deleted environments are removed from the overview but remain in billing history.
- They don’t consume resources after deletion.
- API requests to a deleted environment return a 404 error.