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. Skipped copies can also lower the target’s cache hit rate, through no fault of the target. The target must meet the source’s regional and compliance constraints. A target environment receives the copies on whichever deployment it’s serving. New shadow rules use session-aware sampling by default. Send the samex-session-affinity header value on related requests to have Baseten sample
them together. When Baseten can’t identify a session, it samples requests
individually. Choose random sampling to sample every request independently.
- 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.
- For Expiration, choose how long the rule runs, up to 7 days.
- To change sampling or cancellation, open More options.
- To sample each request independently, select Random sampling.
- 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.
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.