Skip to main content
An environment is a named release target for a model, such as production or staging. It has a stable endpoint and its own resource, autoscaling, monitoring, and promotion settings. Promote a new deployment to update the version that serves the environment without changing the endpoint your client calls. Baseten dashboard showing model environments and their deployments 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.
To change this setting, enable rolling deployments or turn off rolling deployments for the environment. When you promote a deployment, Baseten applies the environment’s scaling and monitoring 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.
The production environment operates like any other environment but has restrictions:
  • 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.
To start shadow traffic:
  1. Sign in to your workspace at app.baseten.co and choose Dedicated Inference in the sidebar, then select your model.
  2. Under Environments, select the source environment.
  3. In the Traffic routing section, choose Add rule.
  4. For Target, select the environment or deployment to receive the copies.
  5. 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.
  6. For Expiration, choose how long the rule runs, up to 7 days.
  7. For Sampling, choose Random to pick each request independently, or Session-aware to keep a session’s requests together.
  8. To cancel a copy when the client cancels the original request, select Propagate client cancellation to the target.
  9. Choose Start shadowing.
The Traffic routing section shows the running rule.To change a shadow rule:
  1. In the source environment’s Traffic routing section, choose Edit.
  2. Change the percentage, expiration, sampling, or cancellation, then choose Save.
To stop shadow traffic:
  1. In the source environment’s Traffic routing section, choose Stop.
  2. Choose Stop rule to confirm.
Session-aware sampling groups requests by the session key the client sends, such as a consistent 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

The baseten 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-autoscaling and update-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.
When Baseten creates a new deployment, it applies the environment’s autoscaling settings to that deployment. After promotion completes, the environment’s promotion cleanup strategy controls the deployment it replaced. If Baseten creates a new deployment from a published source, the new deployment reuses the source image. Promoting a development deployment creates a new published deployment from its current state and triggers an image build.

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
To create a new custom environment during the push, run the following command:
Terminal
Without --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 the environment 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
You can use the environment in your load() method to configure per-environment behavior:
model/model.py
Validate an unassociated deployment first: it should load the default weights. After promotion to production, confirm that initialization uses the production weights through your model’s prediction result or deployment logs. If you use environment-specific configuration in 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 means load() 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:
  1. Sign in to your workspace at app.baseten.co and choose Dedicated Inference in the sidebar, then select your model.
  2. Open the environment’s settings.
  3. Toggle Re-deploy when promoting.
You can also set it through the update environment settings endpoint.
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.