Deploy to Environments
This guide shows you how to deploy variants to environments (development, staging, production) using the Agenta SDK.
Deploying to Environments
To deploy a variant to an environment, use the DeploymentManager.deploy method with the variant reference and environment_slug: The slug of the environment (development, staging, or production).
- Python SDK
- JS/TS
- API
deployment = ag.DeploymentManager.deploy(
app_slug="my-app-slug",
variant_slug="my-variant-slug",
variant_version=None, # Deploys latest version if not specified
environment_slug="staging" # Options: development, staging, production
)
print(f"Deployed to {deployment['environment_slug']}")
// Deploy a variant's latest revision to an environment
const deployResponse = await fetch('https://cloud.agenta.ai/api/applications/revisions/deploy', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'ApiKey YOUR_API_KEY'
},
body: JSON.stringify({
application_ref: { slug: 'my-app-slug' },
application_variant_ref: { slug: 'my-variant-slug' },
environment_ref: { slug: 'staging' },
message: 'Promote latest variant to staging'
})
});
const { application_revision } = await deployResponse.json();
console.log(`Deployed revision ${application_revision.version}`);
# Deploy a variant's latest revision to an environment
curl -X POST "https://cloud.agenta.ai/api/applications/revisions/deploy" \
-H "Content-Type: application/json" \
-H "Authorization: ApiKey YOUR_API_KEY" \
-d '{
"application_ref": { "slug": "my-app-slug" },
"application_variant_ref": { "slug": "my-variant-slug" },
"environment_ref": { "slug": "staging" },
"message": "Promote latest variant to staging"
}'
warning
- Omitting the revision (SDK
variant_version, RESTapplication_revision_ref) deploys the latest revision of the variant. - Only predefined environments with slugs
development,staging, andproductionare currently supported.
Sample Output:
Deployed variant to environment:
{
"app_id": "01963413-3d39-7650-80ce-3ad5d688da6c",
"app_slug": "completion",
"variant_id": "01968c11-6f7c-7773-b273-922c5807be7b",
"variant_slug": "my-variant-slug4",
"variant_version": 5,
"environment_id": "01968c14-c35d-7440-bcc8-9def594f017f",
"environment_slug": "staging",
"environment_version": 2,
"committed_at": "2025-05-01T07:26:08.935406+00:00",
"committed_by": "user@agenta.ai",
"committed_by_id": "0196247a-ec9d-7051-8880-d58279570aa1",
"deployed_at": "2025-05-01T13:41:33.149595+00:00",
"deployed_by": "user@agenta.ai",
"deployed_by_id": "0196247a-ec9d-7051-8880-d58279570aa1"
}
Rolling Back to a Previous Version
To rollback to a previous version, you can deploy a specific version of a variant to an environment:
- Python SDK
- JS/TS
- API
# Deploy a specific version (rollback)
deployment = ag.DeploymentManager.deploy(
app_slug="my-app-slug",
variant_slug="my-variant-slug",
variant_version=3, # Specify the version you want to rollback to
environment_slug="production"
)
print(f"Rolled back to version {deployment['variant_version']}")
// Roll back to a specific revision by version
const deployResponse = await fetch('https://cloud.agenta.ai/api/applications/revisions/deploy', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'ApiKey YOUR_API_KEY'
},
body: JSON.stringify({
application_ref: { slug: 'my-app-slug' },
application_variant_ref: { slug: 'my-variant-slug' },
application_revision_ref: { version: '3' },
environment_ref: { slug: 'production' },
message: 'Rollback to v3'
})
});
const { application_revision } = await deployResponse.json();
console.log(`Rolled back to revision ${application_revision.version}`);
# Roll back to a specific revision by version
curl -X POST "https://cloud.agenta.ai/api/applications/revisions/deploy" \
-H "Content-Type: application/json" \
-H "Authorization: ApiKey YOUR_API_KEY" \
-d '{
"application_ref": { "slug": "my-app-slug" },
"application_variant_ref": { "slug": "my-variant-slug" },
"application_revision_ref": { "version": "3" },
"environment_ref": { "slug": "production" },
"message": "Rollback to v3"
}'
This effectively rolls back the environment to the specified version of the variant.
tip
You can view the full history of deployments and versions in the Agenta UI under the Registry and Deployments pages.
