Hi, from the documentation I've found internally, as this feature is still in public previewbudget policy creation via the SDK is not currently supported. You can try using it via the rest API instead however this also could not yet be rolled out to your workspace.
import requests
# Replace these with your actual values
ACCOUNT_ID = 'your_account_id'
TOKEN = 'your_databricks_oauth_token' # Must have billing admin privileges
# Endpoint for budget policy creation
endpoint = f'https://accounts.azuredatabricks.net/api/2.0/accounts/{ACCOUNT_ID}/budget-policies'
# Customize the payload as needed for your budget policy
payload = {
"name": "Serverless Budget Policy Q4",
"description": "Control spend for serverless endpoints in Q4",
"budget": {
"amount": 5000,
"currency_code": "GBP"
},
"targets": [
{
"type": "ENDPOINT",
"resource_type": "VECTOR_SEARCH",
# or "SERVERLESS_COMPUTE" depending on what you intend
"resource_id": "vs-1234567890abcdef"
}
],
"actions": [
{
"action_type": "NOTIFY",
"threshold_percent": 80,
"notification_emails": ["emma.stowell@databricks.com"]
}
]
}
# Headers for authentication and content type
headers = {
"Authorization": f"Bearer {TOKEN}",
"Content-Type": "application/json"
}
response = requests.post(endpoint, json=payload, headers=headers)
if response.ok:
print("Budget policy created:", response.json())
else:
print("Error creating policy:", response.status_code, response.text)