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 to an environment
const deployResponse = await fetch('https://cloud.agenta.ai/api/variants/configs/deploy', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
variant_ref: {
slug: 'my-variant-slug',
version: null,
id: null
},
environment_ref: {
slug: 'staging',
version: null,
id: null
},
application_ref: {
slug: 'my-app-slug',
version: null,
id: null
}
})
});
const deployment = await deployResponse.json();
console.log(`Deployed to ${deployment.environment_slug}`);
# Deploy a variant to an environment
curl -X POST "https://cloud.agenta.ai/api/variants/configs/deploy" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"variant_ref": {
"slug": "my-variant-slug",
"version": null,
"id": null
},
"environment_ref": {
"slug": "staging",
"version": null,
"id": null
},
"application_ref": {
"slug": "my-app-slug",
"version": null,
"id": null
}
}'
warning
- Deploying a variant without specifying a
variant_versiondeploys the latest version. - 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']}")
// Deploy a specific version (rollback)
const deployResponse = await fetch('https://cloud.agenta.ai/api/variants/configs/deploy', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
variant_ref: {
slug: 'my-variant-slug',
version: 3,
id: null
},
environment_ref: {
slug: 'production',
version: null,
id: null
},
application_ref: {
slug: 'my-app-slug',
version: null,
id: null
}
})
});
const deployment = await deployResponse.json();
console.log(`Rolled back to version ${deployment.variant_version}`);
# Deploy a specific version (rollback)
curl -X POST "https://cloud.agenta.ai/api/variants/configs/deploy" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"variant_ref": {
"slug": "my-variant-slug",
"version": 3,
"id": null
},
"environment_ref": {
"slug": "production",
"version": null,
"id": null
},
"application_ref": {
"slug": "my-app-slug",
"version": null,
"id": null
}
}'
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.
