Get Training Status
curl --request GET \
--url https://api.zerodrift.ai/api/policies/import/{import_id}/train \
--header 'x-api-key: <api-key>'import requests
url = "https://api.zerodrift.ai/api/policies/import/{import_id}/train"
headers = {"x-api-key": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'x-api-key': '<api-key>'}};
fetch('https://api.zerodrift.ai/api/policies/import/{import_id}/train', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.zerodrift.ai/api/policies/import/{import_id}/train",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.zerodrift.ai/api/policies/import/{import_id}/train"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-api-key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.zerodrift.ai/api/policies/import/{import_id}/train")
.header("x-api-key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.zerodrift.ai/api/policies/import/{import_id}/train")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["x-api-key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"import_id": "550e8400-e29b-41d4-a716-446655440000",
"training_run_id": "run-808961af",
"status": "succeeded",
"stage": "complete",
"progress": {
"completed": 4,
"total": 4
},
"error": null
}
Training Studio
Get Training Status
Poll a policy import until its Training Studio adapter is ready
GET
/
api
/
policies
/
import
/
{import_id}
/
train
Get Training Status
curl --request GET \
--url https://api.zerodrift.ai/api/policies/import/{import_id}/train \
--header 'x-api-key: <api-key>'import requests
url = "https://api.zerodrift.ai/api/policies/import/{import_id}/train"
headers = {"x-api-key": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'x-api-key': '<api-key>'}};
fetch('https://api.zerodrift.ai/api/policies/import/{import_id}/train', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.zerodrift.ai/api/policies/import/{import_id}/train",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.zerodrift.ai/api/policies/import/{import_id}/train"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-api-key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.zerodrift.ai/api/policies/import/{import_id}/train")
.header("x-api-key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.zerodrift.ai/api/policies/import/{import_id}/train")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["x-api-key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"import_id": "550e8400-e29b-41d4-a716-446655440000",
"training_run_id": "run-808961af",
"status": "succeeded",
"stage": "complete",
"progress": {
"completed": 4,
"total": 4
},
"error": null
}
Return the current training run for a policy import. Poll after
Train Policy Adapter until
status is succeeded or failed.
The successful poll is part of activation: when Training Studio reports
succeeded, ZeroDrift records the run as the import’s active adapter. A failed
retraining attempt does not replace an earlier working adapter.
Path Parameters
string
required
The policy import whose training run you want to inspect.
Response
string
Policy import associated with the run.
string
Training Studio run identifier.
string
Current run status.
succeeded and failed are terminal.string
Current training pipeline stage, when reported.
object
Training progress details, when reported.
string
Failure detail when
status is failed.{
"import_id": "550e8400-e29b-41d4-a716-446655440000",
"training_run_id": "run-808961af",
"status": "succeeded",
"stage": "complete",
"progress": {
"completed": 4,
"total": 4
},
"error": null
}
Error Responses
| Status | Description |
|---|---|
| 403 | Invalid API key, or the import belongs to another customer |
| 404 | Import not found, or no training run has been started |
| 500 | Import state could not be read or updated |
| 502 | Training Studio status request failed |
| 503 | Training is not configured in this environment |
Complete flow
Training extends the custom-policy flow:- Import Policy.
- Poll Get Import Details
until extraction reaches
pending_review. - Review or simulate the extracted rules, then Activate Rules.
- Train Policy Adapter.
- Poll this endpoint until
statusissucceededorfailed. Stop on either terminal status; do not keep polling a failed run. - If the run
succeeded, enforce content withvalidation_scope.importscontaining the import ID.
Do not submit content for enforcement to a still-training run. ZeroDrift only promotes
training_run_id after a successful status poll; until then, scoped
enforcement follows its configured fallback path.Example
This sample starts training and polls to a terminal state.Python
import time
import requests
API_BASE = "https://api.zerodrift.ai"
API_KEY = "YOUR_API_KEY"
IMPORT_ID = "550e8400-e29b-41d4-a716-446655440000"
URL = f"{API_BASE}/api/policies/import/{IMPORT_ID}/train"
HEADERS = {"x-api-key": API_KEY}
started = requests.post(URL, headers=HEADERS, json={})
started.raise_for_status()
print(started.json())
while True:
response = requests.get(URL, headers=HEADERS)
response.raise_for_status()
training = response.json()
print(training["status"])
if training["status"] in ("succeeded", "failed"):
break
time.sleep(10)
if training["status"] == "failed":
raise SystemExit(training.get("error", "Training failed"))

