Read Deployment Details
Every deployment includes a valohai-metadata.json file with details about the current deployment, version, and endpoint configuration.
Access the metadata
Read and parse the file from your endpoint code:
import json
with open('valohai-metadata.json', 'r') as f:
metadata = json.load(f)
# Access specific values
deployment_name = metadata['deployment']['name']
version_name = metadata['version']['name']
endpoint_name = metadata['endpoint']['name']Common use cases
Log deployment info on startup:
print(f"Starting {metadata['endpoint']['name']} from version {metadata['version']['name']}")Conditional logic based on environment:
if metadata['deployment']['target'] == 'production-cluster':
enable_strict_validation = TrueTrack which model files are loaded:
model_files = [f['datum']['name'] for f in metadata['endpoint']['files']]
print(f"Loaded models: {', '.join(model_files)}")Metadata structure
The JSON contains these top-level keys:
deployment- Deployment details (name, target, URLs)version- Version info (name, commit, creation time)endpoint- Endpoint configuration (resources, files, status)project- Project details (name, owner)meta- Metadata about the metadata file itself
Example metadata file
{
"deployment": {
"name": "fraud-detection-api",
"target": "production-cluster",
"url": "https://app.valohai.com/api/v0/deployments/..."
},
"version": {
"name": "20240315.2",
"enabled": true,
"ctime": "2024-03-15T14:23:11.431914Z"
},
"endpoint": {
"name": "predict",
"cpu_request": 0.1,
"memory_limit": 512,
"files": [
{
"name": "model",
"datum": {
"name": "fraud_model_v2.pkl",
"size": 1048576
}
}
]
},
"project": {
"name": "fraud-detection",
"owner": {"username": "acme"}
}
}Next: Learn about installing additional packages in your deployments.
Last updated
Was this helpful?
