Deployments API
Serve a trained model as a TensorRT endpoint on a GPU: create, call, scale, pause and delete deployments, and stream live video through them.
On this page
A deployment is billed while it’s up, plus its requests’ data transfer; pause it to
stop the meter. Choosing a GPU and keeping cost down: Deployments guide.
Manage deployments with your API key; call one with its own pk_deploy_ token, which create
returns (Calling your deployment).
Regions
A deployment runs in one region, fixed at create: its GPU and its endpoint are both there.
region |
Requests enter |
|---|---|
us-east (the default) |
Virginia |
us-west |
Oregon |
region="auto", the default for create and quote, picks the region
nearest the call; choose the one nearest the cameras and clients that call it. endpoint_url
names the region (https://workflows.pictograph.io/us-west/<slug>/predict), and only that
region answers it. To move a deployment, create another in the new region.
If the region has no free GPU for 30 seconds, a request or stream is also offered GPUs
elsewhere in the US; the first found serves until the deployment goes idle. Requests still
enter, and are priced, in the home region. region_fallback says whether a deployment can fall
back; runtime.fallback counts containers serving elsewhere, and a stream’s open response and
state show fallback.
Provisioning
create returns at once with the deployment provisioning. It turns active in
about a minute, or a few minutes the first time the model is deployed on that GPU at that
precision, while its TensorRT engine builds (unbilled; later deployments skip it). During the
build, engine_build.state is "building" (each model’s started_at, and estimate_s from
earlier builds on that GPU), then "built" (build_s).
wait_until_active waits; the CLI waits with --wait.
A deployment that can’t start is failed with an error_message; it can’t be resumed, so
delete it and create it again. resume provisions a paused deployment the same way,
on the model’s current version. The GPU and precision are fixed at create; update
changes the rest.
Live state
An active deployment’s runtime says what it is doing now (None for any other status).
Reading it never wakes the deployment.
runtime.state |
Means |
|---|---|
live |
Serving, with containers up (and creating starting) |
starting |
creating containers are starting and loading the engine |
waiting |
A request waits for a GPU (since waiting_since), or a warm minimum has no container yet |
asleep |
Scaled to zero; the next request wakes it, in about 10 to 15 seconds when a GPU is free |
unknown |
The state couldn’t be read in time; read it again |
fallback counts the containers serving elsewhere in the US (Regions), and
checked_at is when it was read. Treat an unknown state as new, not an error. The CLI shows
it beside the status, e.g. active · waiting for a GPU 1m42s.
Request limit
There is no request cap by default; cost is bounded by max_containers and your budget.
rate_limit_rpm (1 to 1,000,000 a minute, set at create or update,
0 removes it) caps requests: past it, the endpoint answers 429 rate_limited with
Retry-After. A change reaches the endpoint within 30 seconds.
Price it
compute_options
What a deployment can run with, priced in one region.
Source: Deployments.compute_options
| Arg | Type | Default | Notes |
|---|---|---|---|
region |
str |
"auto" |
Region id, or auto for the one nearest the caller |
offer = client.deployments.compute_options()
for region in offer.regions:
print(region.id, region.label, region.location) # us-east US East Virginia
for option in offer.options:
print(option.gpu_type, option.vram_gb, option.cpu_cores, option.rate_per_min_micro_usd)
for precision in offer.precisions:
print(precision.precision, precision.label, precision.description)
pictograph deployments compute-options
curl -s "https://api.pictograph.io/api/v1/developer/deployments/compute-options" \
-H "X-API-Key: $PICTOGRAPH_API_KEY"
Returns DeploymentComputeOptions
DeploymentComputeOptions · 5 fields
class DeploymentComputeOptions(BaseModel):
"""What a deployment may run with: the regions (and the one these prices are for), each GPU tier (its container and price there) and each precision its engine is built at, the default first."""
region: str | None = None
regions: list[DeploymentRegion] = []
options: list[DeploymentComputeOption] = []
precisions: list[DeploymentComputePrecision] = []
transfer_per_gib_micro_usd: int | None = None
Time each region’s ping_url; the fastest is nearest you.
quote
What a deployment would cost while it’s up, before you create it.
Source: Deployments.quote
| Arg | Type | Default | Notes |
|---|---|---|---|
gpu_type |
DeploymentGpuType |
"t4" |
t4 (16 GB), l4 (24 GB) or a100 (40 GB) |
min_containers |
int |
0 |
Containers kept warm; 0 quotes scale-to-zero |
max_containers |
int |
1 |
Most containers it scales to |
region |
str |
"auto" |
Region id, or auto for the one nearest the caller; each region has its own price |
quote = client.deployments.quote(
gpu_type="t4",
min_containers=0,
max_containers=2,
region="us-west",
)
print(quote.rate_per_min_micro_usd, quote.cost_per_hour_micro_usd, quote.max_cost_per_hour_micro_usd)
print(quote.billing_note)
pictograph deployments quote --gpu t4 --min-containers 0 --max-containers 2 --region us-west
curl -s "https://api.pictograph.io/api/v1/developer/deployments/quote?gpu_type=t4&min_containers=0&max_containers=2®ion=us-west" \
-H "X-API-Key: $PICTOGRAPH_API_KEY"
Returns DeploymentQuote
DeploymentQuote · 10 fields
class DeploymentQuote(BaseModel):
"""What a deployment costs while it is up, before creating it, in micro-USD."""
rate_per_min_micro_usd: int
container_cost_per_hour_micro_usd: int | None = None
cost_per_hour_micro_usd: int
cost_per_day_micro_usd: int
warm_cost_per_hour_micro_usd: int | None = None
warm_cost_per_day_micro_usd: int | None = None
max_cost_per_hour_micro_usd: int | None = None
transfer_per_gib_micro_usd: int | None = None
scale_to_zero: bool
billing_note: str
Each price is an hour of:
cost_per_hour_micro_usd: running (min_containerscontainers, or one if it scales to zero)warm_cost_per_hour_micro_usd: the containers kept warm (0when it scales to zero)max_cost_per_hour_micro_usd: allmax_containersrunning
transfer_per_gib_micro_usd is a GiB of data transfer (the images sent and the answers),
charged on top, the same on every GPU and in every region.
Manage
create
Deploy a trained model. The response carries its pk_deploy_ token, which the API never
returns again (a member can reveal it in the app: Run on the deployment, then
Overview). Wait for it with wait_until_active.
Source: Deployments.create
| Arg | Type | Default | Notes |
|---|---|---|---|
model |
str |
required | Model name or id; must be ready |
name |
str | None |
None |
Unique among your live deployments (default: the model’s name) |
region |
str |
"auto" |
us-east, us-west, or auto (nearest the caller); can’t change later (Regions) |
gpu_type |
DeploymentGpuType |
"t4" |
t4 (16 GB), l4 (24 GB) or a100 (40 GB) |
precision |
DeploymentPrecision |
"fp32" |
fp32 serves the model as trained; fp16 is faster and as accurate, but not output-identical |
min_containers |
int |
0 |
Containers kept warm, and billed, 0 to 5; 0 scales to zero |
max_containers |
int |
1 |
Most containers it scales to, 1 to 10 |
scaledown_window |
int |
60 |
Seconds a container stays after its last request, 2 to 3600 |
rate_limit_rpm |
int | None |
None |
Max requests a minute before the endpoint answers 429 (request limit); none by default |
inference_config |
dict[str, Any] | None |
None |
Per-model defaults, e.g. a confidence threshold |
created = client.deployments.create(
model="Swift Falcon",
name="prod-detector",
region="us-west",
gpu_type="t4",
precision="fp32",
min_containers=0,
max_containers=2,
scaledown_window=60,
)
print(created.deployment.id, created.deployment.status) # ... provisioning
print(created.auth_token) # pk_deploy_... - store it now
pictograph deployments create "Swift Falcon" \
--name prod-detector --region us-west --gpu t4 --precision fp32 --min 0 --max 2 --scaledown 60 --wait
curl -s -X POST "https://api.pictograph.io/api/v1/developer/deployments/" \
-H "X-API-Key: $PICTOGRAPH_API_KEY" -H "Content-Type: application/json" \
-d '{"model": "Swift Falcon", "name": "prod-detector", "region": "us-west", "gpu_type": "t4", "precision": "fp32", "min_containers": 0, "max_containers": 2, "scaledown_window": 60}'
Returns CreatedDeployment
CreatedDeployment · 2 fields
class CreatedDeployment(BaseModel):
"""What `create` returns: the deployment and its token, shown once."""
deployment: Deployment
# The deployment's bearer token. The API returns it only here; a member can reveal
# it again in the app.
auth_token: str
wait_until_active
Wait until a deployment is active after create or resume
(how long).
Source: Deployments.wait_until_active
| Arg | Type | Default | Notes |
|---|---|---|---|
deployment |
str | Deployment |
required | Deployment name or id, or the Deployment that create or resume returned |
timeout |
float |
900.0 |
Max seconds to wait |
poll_interval |
float |
3.0 |
Seconds between checks |
deployment = client.deployments.wait_until_active(
deployment="prod-detector",
timeout=900.0,
)
print(deployment.status, deployment.endpoint_url) # active https://.../predict
pictograph deployments wait prod-detector --timeout 900
# There is no wait endpoint: poll the deployment until its status is "active".
curl -s "https://api.pictograph.io/api/v1/developer/deployments/prod-detector" \
-H "X-API-Key: $PICTOGRAPH_API_KEY"
Returns Deployment
Deployment · 37 fields
class Deployment(BaseModel):
"""A model inference deployment: provisioning, active, paused, failed or terminated."""
id: str
organization_id: str
model_id: str
version_id: str | None = None
name: str
readme: str | None = None
status: Literal['draft', 'provisioning', 'active', 'paused', 'failed', 'terminated']
region: str | None = None
compute_type: Literal['cpu', 'gpu'] = 'gpu'
gpu_type: str | None = None
precision: str = 'fp32'
min_containers: int
max_containers: int
scaledown_window: int
rate_limit_rpm: int | None = None
endpoint_url: str | None = None
auth_token_prefix: str | None = None
inference_config: dict[str, Any] = {}
engine_build: EngineBuild | None = None
error_message: str | None = None
cost_rate_per_min: int = 0
cost_per_hour_micro_usd: int | None = None
max_cost_per_hour_micro_usd: int | None = None
transfer_per_gib_micro_usd: int | None = None
accrued_cost_micro_usd: int = 0
uptime_seconds: int = 0
transfer_bytes: int = 0
transfer_cost_micro_usd: int = 0
metrics: DeploymentMetrics | None = None
runtime: DeploymentRuntime | None = None
stream_limit: int = 0
region_fallback: bool = False
logged: bool | None = None
created_at: datetime | None = None
updated_at: datetime | None = None
started_at: datetime | None = None
paused_at: datetime | None = None
A deployment that scales to zero may be asleep once active; its first request wakes it. A
failure raises ApiError with code job_failed (job_cancelled if it’s paused or deleted
meanwhile) and the deployment as its response. The CLI exits 1 on a failure and 10 on a
timeout.
get
One deployment. Reading it never wakes it.
Source: Deployments.get
| Arg | Type | Default | Notes |
|---|---|---|---|
deployment |
str |
required | Deployment name or id |
deployment = client.deployments.get(deployment="prod-detector")
print(deployment.status, deployment.gpu_type, deployment.precision, deployment.endpoint_url)
if deployment.runtime is not None:
print(deployment.runtime.state) # live, starting, waiting, asleep or unknown
if deployment.engine_build is not None:
print(deployment.engine_build.state) # building, then built
pictograph deployments get prod-detector
curl -s "https://api.pictograph.io/api/v1/developer/deployments/prod-detector" \
-H "X-API-Key: $PICTOGRAPH_API_KEY"
Returns Deployment
Deployment · 37 fields
class Deployment(BaseModel):
"""A model inference deployment: provisioning, active, paused, failed or terminated."""
id: str
organization_id: str
model_id: str
version_id: str | None = None
name: str
readme: str | None = None
status: Literal['draft', 'provisioning', 'active', 'paused', 'failed', 'terminated']
region: str | None = None
compute_type: Literal['cpu', 'gpu'] = 'gpu'
gpu_type: str | None = None
precision: str = 'fp32'
min_containers: int
max_containers: int
scaledown_window: int
rate_limit_rpm: int | None = None
endpoint_url: str | None = None
auth_token_prefix: str | None = None
inference_config: dict[str, Any] = {}
engine_build: EngineBuild | None = None
error_message: str | None = None
cost_rate_per_min: int = 0
cost_per_hour_micro_usd: int | None = None
max_cost_per_hour_micro_usd: int | None = None
transfer_per_gib_micro_usd: int | None = None
accrued_cost_micro_usd: int = 0
uptime_seconds: int = 0
transfer_bytes: int = 0
transfer_cost_micro_usd: int = 0
metrics: DeploymentMetrics | None = None
runtime: DeploymentRuntime | None = None
stream_limit: int = 0
region_fallback: bool = False
logged: bool | None = None
created_at: datetime | None = None
updated_at: datetime | None = None
started_at: datetime | None = None
paused_at: datetime | None = None
list
One page of deployments.
Source: Deployments.list
| Arg | Type | Default | Notes |
|---|---|---|---|
model |
str | None |
None |
Only this model’s deployments, by name or id |
name |
str | None |
None |
Only the deployment with this exact name |
status |
DeploymentStatus | None |
None |
Only this status: provisioning, active, paused, failed or terminated |
limit |
int |
50 |
Page size |
offset |
int |
0 |
Items to skip |
for deployment in client.deployments.list(status="active", limit=50):
print(deployment.name, deployment.status, deployment.endpoint_url)
pictograph deployments list --status active --limit 50
curl -s "https://api.pictograph.io/api/v1/developer/deployments/?status=active&limit=50" \
-H "X-API-Key: $PICTOGRAPH_API_KEY"
Returns list[Deployment]
Deployment · 37 fields
class Deployment(BaseModel):
"""A model inference deployment: provisioning, active, paused, failed or terminated."""
id: str
organization_id: str
model_id: str
version_id: str | None = None
name: str
readme: str | None = None
status: Literal['draft', 'provisioning', 'active', 'paused', 'failed', 'terminated']
region: str | None = None
compute_type: Literal['cpu', 'gpu'] = 'gpu'
gpu_type: str | None = None
precision: str = 'fp32'
min_containers: int
max_containers: int
scaledown_window: int
rate_limit_rpm: int | None = None
endpoint_url: str | None = None
auth_token_prefix: str | None = None
inference_config: dict[str, Any] = {}
engine_build: EngineBuild | None = None
error_message: str | None = None
cost_rate_per_min: int = 0
cost_per_hour_micro_usd: int | None = None
max_cost_per_hour_micro_usd: int | None = None
transfer_per_gib_micro_usd: int | None = None
accrued_cost_micro_usd: int = 0
uptime_seconds: int = 0
transfer_bytes: int = 0
transfer_cost_micro_usd: int = 0
metrics: DeploymentMetrics | None = None
runtime: DeploymentRuntime | None = None
stream_limit: int = 0
region_fallback: bool = False
logged: bool | None = None
created_at: datetime | None = None
updated_at: datetime | None = None
started_at: datetime | None = None
paused_at: datetime | None = None
iter
Every deployment, fetched page by page.
Source: Deployments.iter
| Arg | Type | Default | Notes |
|---|---|---|---|
model |
str | None |
None |
As in list |
name |
str | None |
None |
As in list |
status |
DeploymentStatus | None |
None |
As in list |
page_size |
int |
50 |
Items fetched per request |
max_total |
int | None |
None |
Stop after this many items |
for deployment in client.deployments.iter(page_size=50):
print(deployment.name, deployment.status)
curl -s "https://api.pictograph.io/api/v1/developer/deployments/?limit=50&offset=0" \
-H "X-API-Key: $PICTOGRAPH_API_KEY"
# The CLI does not auto-page; this is a single page.
pictograph deployments list
Returns OffsetPager[Deployment]
Deployment · 37 fields
class Deployment(BaseModel):
"""A model inference deployment: provisioning, active, paused, failed or terminated."""
id: str
organization_id: str
model_id: str
version_id: str | None = None
name: str
readme: str | None = None
status: Literal['draft', 'provisioning', 'active', 'paused', 'failed', 'terminated']
region: str | None = None
compute_type: Literal['cpu', 'gpu'] = 'gpu'
gpu_type: str | None = None
precision: str = 'fp32'
min_containers: int
max_containers: int
scaledown_window: int
rate_limit_rpm: int | None = None
endpoint_url: str | None = None
auth_token_prefix: str | None = None
inference_config: dict[str, Any] = {}
engine_build: EngineBuild | None = None
error_message: str | None = None
cost_rate_per_min: int = 0
cost_per_hour_micro_usd: int | None = None
max_cost_per_hour_micro_usd: int | None = None
transfer_per_gib_micro_usd: int | None = None
accrued_cost_micro_usd: int = 0
uptime_seconds: int = 0
transfer_bytes: int = 0
transfer_cost_micro_usd: int = 0
metrics: DeploymentMetrics | None = None
runtime: DeploymentRuntime | None = None
stream_limit: int = 0
region_fallback: bool = False
logged: bool | None = None
created_at: datetime | None = None
updated_at: datetime | None = None
started_at: datetime | None = None
paused_at: datetime | None = None
update
Change a deployment’s name, README, autoscaling or request limit; only what you pass changes. An active deployment takes a scaling change at once, without a restart; a provisioning or paused one when it next starts. A rename keeps its endpoint and token. To change the GPU or precision, deploy again.
Source: Deployments.update
| Arg | Type | Default | Notes |
|---|---|---|---|
deployment |
str |
required | Deployment name or id |
min_containers |
int | None |
None |
As in create |
max_containers |
int | None |
None |
As in create; at least min_containers |
scaledown_window |
int | None |
None |
As in create |
name |
str | None |
None |
New name, unique among your live deployments; up to 100 characters, no / |
readme |
str | None |
None |
README in Markdown, up to 20,000 characters; "" clears it |
rate_limit_rpm |
int | None |
None |
New request limit; 0 removes it |
deployment = client.deployments.update(
deployment="prod-detector",
min_containers=1,
max_containers=3,
scaledown_window=300,
readme="Dock cameras, 6am - 10pm.",
)
print(deployment.status, deployment.min_containers, deployment.max_containers) # active 1 3
pictograph deployments update prod-detector \
--min-containers 1 --max-containers 3 --scaledown-window 300 \
--readme "Dock cameras, 6am - 10pm."
curl -s -X PATCH "https://api.pictograph.io/api/v1/developer/deployments/prod-detector" \
-H "X-API-Key: $PICTOGRAPH_API_KEY" -H "Content-Type: application/json" \
-d '{"min_containers": 1, "max_containers": 3, "scaledown_window": 300, "readme": "Dock cameras, 6am - 10pm."}'
Returns Deployment
Deployment · 37 fields
class Deployment(BaseModel):
"""A model inference deployment: provisioning, active, paused, failed or terminated."""
id: str
organization_id: str
model_id: str
version_id: str | None = None
name: str
readme: str | None = None
status: Literal['draft', 'provisioning', 'active', 'paused', 'failed', 'terminated']
region: str | None = None
compute_type: Literal['cpu', 'gpu'] = 'gpu'
gpu_type: str | None = None
precision: str = 'fp32'
min_containers: int
max_containers: int
scaledown_window: int
rate_limit_rpm: int | None = None
endpoint_url: str | None = None
auth_token_prefix: str | None = None
inference_config: dict[str, Any] = {}
engine_build: EngineBuild | None = None
error_message: str | None = None
cost_rate_per_min: int = 0
cost_per_hour_micro_usd: int | None = None
max_cost_per_hour_micro_usd: int | None = None
transfer_per_gib_micro_usd: int | None = None
accrued_cost_micro_usd: int = 0
uptime_seconds: int = 0
transfer_bytes: int = 0
transfer_cost_micro_usd: int = 0
metrics: DeploymentMetrics | None = None
runtime: DeploymentRuntime | None = None
stream_limit: int = 0
region_fallback: bool = False
logged: bool | None = None
created_at: datetime | None = None
updated_at: datetime | None = None
started_at: datetime | None = None
paused_at: datetime | None = None
pause
Pause a deployment: its containers and its billing stop.
Source: Deployments.pause
| Arg | Type | Default | Notes |
|---|---|---|---|
deployment |
str |
required | Deployment name or id |
deployment = client.deployments.pause(deployment="prod-detector")
print(deployment.status) # paused - uptime billing stops here
pictograph deployments pause prod-detector
curl -s -X POST "https://api.pictograph.io/api/v1/developer/deployments/prod-detector/pause" \
-H "X-API-Key: $PICTOGRAPH_API_KEY"
Returns Deployment
Deployment · 37 fields
class Deployment(BaseModel):
"""A model inference deployment: provisioning, active, paused, failed or terminated."""
id: str
organization_id: str
model_id: str
version_id: str | None = None
name: str
readme: str | None = None
status: Literal['draft', 'provisioning', 'active', 'paused', 'failed', 'terminated']
region: str | None = None
compute_type: Literal['cpu', 'gpu'] = 'gpu'
gpu_type: str | None = None
precision: str = 'fp32'
min_containers: int
max_containers: int
scaledown_window: int
rate_limit_rpm: int | None = None
endpoint_url: str | None = None
auth_token_prefix: str | None = None
inference_config: dict[str, Any] = {}
engine_build: EngineBuild | None = None
error_message: str | None = None
cost_rate_per_min: int = 0
cost_per_hour_micro_usd: int | None = None
max_cost_per_hour_micro_usd: int | None = None
transfer_per_gib_micro_usd: int | None = None
accrued_cost_micro_usd: int = 0
uptime_seconds: int = 0
transfer_bytes: int = 0
transfer_cost_micro_usd: int = 0
metrics: DeploymentMetrics | None = None
runtime: DeploymentRuntime | None = None
stream_limit: int = 0
region_fallback: bool = False
logged: bool | None = None
created_at: datetime | None = None
updated_at: datetime | None = None
started_at: datetime | None = None
paused_at: datetime | None = None
resume
Resume a paused deployment; it provisions again on its model’s current version.
Source: Deployments.resume
| Arg | Type | Default | Notes |
|---|---|---|---|
deployment |
str |
required | Deployment name or id |
deployment = client.deployments.resume(deployment="prod-detector")
print(deployment.status) # provisioning
deployment = client.deployments.wait_until_active(deployment=deployment)
print(deployment.status, deployment.endpoint_url) # active ...
pictograph deployments resume prod-detector --wait
curl -s -X POST "https://api.pictograph.io/api/v1/developer/deployments/prod-detector/resume" \
-H "X-API-Key: $PICTOGRAPH_API_KEY"
Returns Deployment
Deployment · 37 fields
class Deployment(BaseModel):
"""A model inference deployment: provisioning, active, paused, failed or terminated."""
id: str
organization_id: str
model_id: str
version_id: str | None = None
name: str
readme: str | None = None
status: Literal['draft', 'provisioning', 'active', 'paused', 'failed', 'terminated']
region: str | None = None
compute_type: Literal['cpu', 'gpu'] = 'gpu'
gpu_type: str | None = None
precision: str = 'fp32'
min_containers: int
max_containers: int
scaledown_window: int
rate_limit_rpm: int | None = None
endpoint_url: str | None = None
auth_token_prefix: str | None = None
inference_config: dict[str, Any] = {}
engine_build: EngineBuild | None = None
error_message: str | None = None
cost_rate_per_min: int = 0
cost_per_hour_micro_usd: int | None = None
max_cost_per_hour_micro_usd: int | None = None
transfer_per_gib_micro_usd: int | None = None
accrued_cost_micro_usd: int = 0
uptime_seconds: int = 0
transfer_bytes: int = 0
transfer_cost_micro_usd: int = 0
metrics: DeploymentMetrics | None = None
runtime: DeploymentRuntime | None = None
stream_limit: int = 0
region_fallback: bool = False
logged: bool | None = None
created_at: datetime | None = None
updated_at: datetime | None = None
started_at: datetime | None = None
paused_at: datetime | None = None
delete
Delete a deployment: its endpoint and token stop working and its billing stops. It can’t be undone.
Source: Deployments.delete
| Arg | Type | Default | Notes |
|---|---|---|---|
deployment |
str |
required | Deployment name or id |
client.deployments.delete(deployment="prod-detector")
pictograph deployments delete prod-detector --yes
curl -s -X DELETE "https://api.pictograph.io/api/v1/developer/deployments/prod-detector" \
-H "X-API-Key: $PICTOGRAPH_API_KEY"
Returns None
bulk_pause
Pause several deployments in one call. A name that isn’t found is listed in not_found.
Source: Deployments.bulk_pause
| Arg | Type | Default | Notes |
|---|---|---|---|
deployments |
Sequence[str] |
required | Deployment names or ids |
result = client.deployments.bulk_pause(
deployments=["prod-detector", "staging-detector"],
)
print(result.count, "changed;", result.not_found, "not found")
# Several names make one call.
pictograph deployments pause prod-detector staging-detector
curl -s -X POST "https://api.pictograph.io/api/v1/developer/deployments/bulk-pause" \
-H "X-API-Key: $PICTOGRAPH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"deployments": ["prod-detector", "staging-detector"]}'
Returns BulkActionResult
BulkActionResult · 3 fields
class BulkActionResult(BaseModel):
"""What a bulk change (pause, resume, cancel) did."""
# Ids this call changed.
succeeded: list[str] = []
# Ids not found, or not in a state it could change.
not_found: list[str] = []
# How many were changed.
count: int = 0
bulk_resume
Resume several paused deployments in one call; each provisions again. A name that isn’t found is listed in not_found.
Source: Deployments.bulk_resume
| Arg | Type | Default | Notes |
|---|---|---|---|
deployments |
Sequence[str] |
required | Deployment names or ids |
result = client.deployments.bulk_resume(
deployments=["prod-detector", "staging-detector"],
)
print(result.count, "changed;", result.not_found, "not found")
# Several names make one call.
pictograph deployments resume prod-detector staging-detector
curl -s -X POST "https://api.pictograph.io/api/v1/developer/deployments/bulk-resume" \
-H "X-API-Key: $PICTOGRAPH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"deployments": ["prod-detector", "staging-detector"]}'
Returns BulkActionResult
BulkActionResult · 3 fields
class BulkActionResult(BaseModel):
"""What a bulk change (pause, resume, cancel) did."""
# Ids this call changed.
succeeded: list[str] = []
# Ids not found, or not in a state it could change.
not_found: list[str] = []
# How many were changed.
count: int = 0
bulk_delete
Delete several deployments in one call. A name that isn’t found is listed in not_found.
Source: Deployments.bulk_delete
| Arg | Type | Default | Notes |
|---|---|---|---|
deployments |
Sequence[str] |
required | Deployment names or ids |
result = client.deployments.bulk_delete(
deployments=["prod-detector", "staging-detector"],
)
print(result.count, "changed;", result.not_found, "not found")
# Several names make one call.
pictograph deployments delete prod-detector staging-detector --yes
curl -s -X POST "https://api.pictograph.io/api/v1/developer/deployments/bulk-delete" \
-H "X-API-Key: $PICTOGRAPH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"deployments": ["prod-detector", "staging-detector"]}'
Returns BulkDeleteResult
BulkDeleteResult · 3 fields
class BulkDeleteResult(BaseModel):
"""What a bulk delete removed."""
# Ids that existed and were deleted.
succeeded: list[str] = []
# Ids that were not found.
not_found: list[str] = []
# How many were deleted.
count: int = 0
# The same as succeeded.
@property
def deleted(self) -> list[str]: ...
Calling your deployment
Call a deployment’s endpoint_url (it ends in /predict) with its pk_deploy_ token as a
bearer, not your API key.
Source: DeploymentClient
infer arg |
Type | Default | Notes |
|---|---|---|---|
image |
str | bytes | Path |
required | File path, http(s):// URL or bytes |
confidence |
float | None |
None |
Minimum score, overriding the deployment’s default |
class_filter |
list[str] | None |
None |
Only these classes |
top_k |
int | None |
None |
Predictions to return (classifiers only) |
from pictograph import Client, DetectionResult
client = Client()
deployment = client.deployments.get(deployment="prod-detector")
# `task=` narrows the result type, exactly as it does on get_model.
infer = client.deployments.connect(
deployment=deployment,
api_key="pk_deploy_...",
task="object_detection",
)
result: DetectionResult = infer.infer("photo.jpg", confidence=0.4)
for prediction in result.predictions:
print(prediction.name, round(prediction.confidence, 2), prediction.bounding_box)
# infer_raw(...) returns the endpoint's JSON untouched.
# --endpoint makes the pk_deploy_ token the only credential needed.
pictograph deployments predict prod-detector photo.jpg \
--token "pk_deploy_..." --confidence 0.4
# A video's sampled frames, or a dataset's images (read-only), one JSON line each:
pictograph deployments predict prod-detector --video aisle.mp4 --token "pk_deploy_..."
# A local file as multipart:
curl -s -X POST "$ENDPOINT_URL" \
-H "Authorization: Bearer pk_deploy_..." \
-F "file=@photo.jpg"
# Or a URL / base64 image as JSON, with options inline:
curl -s -X POST "$ENDPOINT_URL" \
-H "Authorization: Bearer pk_deploy_..." -H "Content-Type: application/json" \
-d '{"image": {"type": "url", "value": "https://example.com/photo.jpg"}, "confidence": 0.4}'
$ENDPOINT_URL is the deployment’s endpoint_url. The response is
{"model_type": ..., "predictions": [...]} (plus tags from a classifier). Every response
carries X-Request-Id; a successful one also carries X-Pictograph-Device: cuda and
Server-Timing (decode, infer and total milliseconds), which the SDK’s result reads as
device and inference_ms.
Given the URL, the token is the only credential: DeploymentClient(endpoint_url, "pk_deploy_...", task="object_detection"), or --endpoint <url> --token <token> on the CLI.
connect
A client for one deployment, called with its token: infer(...) returns the typed result
for its task, and infer_raw(...) the endpoint’s JSON.
Source: Deployments.connect
| Arg | Type | Default | Notes |
|---|---|---|---|
deployment |
Deployment |
required | The deployment, as get, create or wait_until_active return it |
api_key |
str |
required | Its pk_deploy_ token, from create (or revealed in the app) |
task |
TaskName | None |
None |
Narrows the result type; None reads it from the deployment |
timeout |
float |
150.0 |
Seconds a prediction may take; longer than a sleeping deployment takes to wake |
deployment = client.deployments.get(deployment="prod-detector")
endpoint = client.deployments.connect(
deployment=deployment,
api_key="pk_deploy_...",
task="object_detection",
)
result = endpoint.infer("photo.jpg", confidence=0.4)
# No `connect` command - it returns an SDK object, not a request. The CLI
# reaches the same endpoint directly:
pictograph deployments predict prod-detector ./photo.jpg --token pk_deploy_...
# `connect` builds a client locally and issues no request of its own. What it
# then calls is the deployment's endpoint:
curl -s -X POST "$ENDPOINT_URL" \
-H "Authorization: Bearer pk_deploy_..." \
-F "file=@photo.jpg"
Returns DeploymentClient[Any]
Endpoint errors
The endpoint names what went wrong in error; the SDK raises the matching typed error
with that name as e.code and a fix saying what to do.
| Status | error |
Exception | Cause |
|---|---|---|---|
| 400 | could_not_decode_image, no_image_provided, invalid_option |
ValidationError |
The image couldn’t be read, or an option was refused |
| 401 | unauthorized |
AuthError |
Not this deployment’s pk_deploy_ token |
| 404 | deployment_not_found |
NotFoundError |
No deployment at this URL (a deleted one stops answering) |
| 409 | deployment_not_active |
ConflictError |
Still provisioning, or paused; wait for it or resume it |
| 413 | request_too_large |
ApiError |
The request is over 64 MiB |
| 429 | rate_limited |
RateLimitError |
Over its request limit (only when set); wait Retry-After, or raise or remove the limit |
| 502 | deployment_unreachable, deployment_unavailable |
ServerError |
Its server couldn’t be reached; retry shortly |
| 503 | deployment_starting |
ServerError |
A scaled-to-zero deployment’s container didn’t start within two minutes; retry after Retry-After |
| 503 | overloaded |
ServerError |
At capacity; retry after Retry-After, or raise max_containers |
| 503 | gateway_unavailable |
ServerError |
The endpoint couldn’t look up the deployment; retry after Retry-After |
| 504 | inference_timeout |
ServerError |
The model didn’t answer in time |
DeploymentClient retries a 429, a 5xx and a network failure (twice, by default), waiting
out a Retry-After.
Streams
A stream sends live video to an active deployment, with its token, and returns each frame’s results as it is processed. The app, the browser and the REST protocol: Streams guide.
Source: DeploymentClient.open_stream
open_stream arg |
Type | Default | Notes |
|---|---|---|---|
source |
str |
required | rtsp://... or rtsps://... (RTSP camera), https://... (WHEP camera), or "whip" to send video yourself |
overlay |
bool |
True |
Draw results on the live view |
stream |
bool |
True |
Send the live view’s pictures; with False, results, events, outputs and the log continue |
transport |
"auto", "tcp", "udp" |
None (tcp) |
RTSP only: "tcp" over the RTSP connection (works through NAT and firewalls), "auto" tries UDP first, "udp" only if the camera’s UDP reaches the deployment |
buffer_mode |
"auto", "none" |
None (auto) |
RTSP only: "none" keeps the sender’s timestamps, so a streamed recording is timed like its file |
reconnect |
"always", "never" |
None (always) |
RTSP only: "never" ends the stream at a recording’s end, after its last frame (ended == "source_ended") |
outputs |
RunOutputs | None |
None |
Workflow streams only: what to write beside the log (annotated_video, event_capture, passive_capture, webhook; live outputs) |
infer = client.deployments.connect(
deployment=deployment,
api_key="pk_deploy_...",
task="object_detection",
)
with infer.open_stream(source="rtsp://camera.example.com:554/live") as stream:
for frame in stream.frames():
print(frame.index, frame.latency_ms.engine, len(frame.result.predictions))
# One JSON line per frame, for 60 seconds; the stream stops when the command does.
pictograph deployments stream prod-detector rtsp://camera.example.com:554/live \
--token "pk_deploy_..." --seconds 60
# "whip": prints where to send the video, then each frame's results.
pictograph deployments stream prod-detector whip --token "pk_deploy_..." --frames 300
# Fail with exit code 9 (stream_stalled) after 5 seconds without a frame.
pictograph deployments stream prod-detector rtsp://camera.example.com:554/live \
--token "pk_deploy_..." --idle-timeout 5
# Results only: no live view is drawn or encoded.
pictograph deployments stream prod-detector rtsp://camera.example.com:554/live \
--token "pk_deploy_..." --no-stream
# Streams open at the endpoint_url with /sessions in place of /predict.
curl -s -X POST "https://workflows.pictograph.io/us-west/7f3a91c2/sessions" \
-H "Authorization: Bearer pk_deploy_..." -H "Content-Type: application/json" \
-d '{"source": {"kind": "rtsp", "uri": "rtsp://camera.example.com:554/live"}}'
Returns a DeploymentStream:
| Member | What it is |
|---|---|
frames(idle_timeout=None) |
Yields a StreamFrame per frame until the stream ends; with idle_timeout, raises StreamStalledError after that many seconds without a frame |
messages(idle_timeout=None) |
Yields every raw message: frames, events, and a stats message each second (a heartbeat with each source’s last_frame_s while no frame comes) |
set_overlay(on) |
Turns drawing on the live view on or off from the next frame; returns the new setting |
set_stream(on) |
Turns the live view’s pictures on or off from the next frame (back on, it starts on a keyframe); returns the new setting |
state() |
A StreamState: session, kind, opened_at, expires_at and engine (source, viewers, overlay, stream, and looks_skipped: frames not drawn because the live view was off) |
stop() |
Stops the stream (also when its with block ends); for a joined run’s live view, stops watching |
whep_url |
The live view, for any WHEP player, with the deployment token |
whip_url |
Where a "whip" stream’s video goes; None for a camera |
results_url |
The WebSocket frames() reads |
id, kind, overlay, stream, stream_limit, opened_at, expires_at |
From the open; overlay and stream track set_overlay and set_stream; a run’s live view has kind "run" |
joined |
True for a stream joined with join_stream |
outputs |
A workflow stream’s outputs as resolved at the open (WorkflowRunWrites); None writes only its log |
ended |
Why it ended: stopped, source_ended, idle, time_limit, container_stopped or ended, or for a run’s live view run_completed, run_failed or run_cancelled; None while running |
Each StreamFrame has result (the typed result infer() returns), index, pts,
latency_ms, capture_time and capture_ns (capture time on the sender’s clock; None until
the sender’s first report), capture_latency_ms (capture to result, on your clock), width,
height and message.
A deployment runs up to four streams per container (stream_limit in all). If it’s asleep,
the open waits about 20 seconds for a container to start.
join_stream(session) joins a running stream by id instead of opening one, such as a
workflow run’s live view (the run’s live_view.session;
watch_run finds it for you). It returns a
DeploymentStream with joined True and kind "run", which ends with its run; stop()
only stops watching. The join waits up to a minute for the run’s first frames.
Stream errors
| Status | error |
Exception | Cause and fix |
|---|---|---|---|
| 400 | invalid_source, unsafe_source |
ValidationError |
The source isn’t "whip" or an rtsp://, rtsps:// or https:// camera reachable from the internet |
| 400 | invalid_source_option |
ValidationError |
transport, buffer_mode or reconnect on a non-RTSP source, or an unknown value |
| 400 | invalid_request_body, invalid_option |
ValidationError |
The body is not JSON, or overlay or stream is not true or false |
| 400, 404, 409 | invalid_outputs |
ValidationError, NotFoundError, ConflictError |
outputs on a model’s deployment, or outputs the workflow’s stream can’t write (output names which): a missing dataset or webhook endpoint is a 404; a dataset in cold storage, or an annotated video the endpoint can’t write yet, a 409 |
| 401 | unauthorized |
AuthError |
Not this deployment’s pk_deploy_ token |
| 404 | deployment_not_found, wrong_region |
NotFoundError |
Wrong URL; use the deployment’s endpoint_url as is |
| 404, 410 | session_not_found, session_ended |
NotFoundError, ApiError |
The stream has ended: open a new one (a run’s live view ends with its run) |
| 406 | - | ApiError |
The video or the player does not support H.264 |
| 409 | deployment_not_active |
ConflictError |
The deployment is paused or still provisioning |
| 409 | streams_unavailable |
ConflictError |
The deployment predates streams; pause and resume it once |
| 409 | run_live_view |
ConflictError |
DELETE on a run’s live view; cancel the run instead |
| 413 | request_too_large |
ApiError |
The request is over 256 KiB |
| 429 | stream_limit |
RateLimitError |
It already runs stream_limit streams; stop one, or raise max_containers |
| 502 | session_failed, deployment_unreachable, deployment_unavailable |
ServerError |
The stream didn’t start; retry (detail says why) |
| 503 | deployment_starting |
ServerError |
No container had started after about 25 seconds (its GPU is still being found); asked again automatically for up to four minutes, and 30 seconds into the wait the deployment’s fallback elsewhere in the US is asked too |
| 503 | sessions_unavailable, gateway_unavailable |
ServerError |
Retry shortly |
| 504 | session_timeout |
ServerError |
Retry |
| - | stream_switch_unavailable |
ConflictError |
set_stream on an endpoint without the stream switch (raised before any request); idle endpoints get it automatically, or pause and resume to get it now |
| - | engine_starting |
ServerError |
join_stream: the run’s engine didn’t answer within a minute (raised by the SDK); join again shortly |
While you read frames(), a dropped connection reconnects; if the stream’s engine stops,
frames() raises ServerError (code session_failed).
Common errors
| Status | Exception | Cause |
|---|---|---|
| 400 | ValidationError |
An unknown gpu_type or precision, max_containers below min_containers, an update that changes nothing, or a model that isn’t ready |
| 402 | PaymentRequiredError |
Not enough credit to provision, resume or keep more containers warm |
| 403 | ForbiddenError |
A key below member (create, update, pause, resume, delete) |
| 404 | NotFoundError |
The deployment or model doesn’t exist |
| 409 | ConflictError |
A name in use, an action the status doesn’t allow (such as changing a failed deployment), an update that collided with another change (retry), or resuming an old CPU deployment (deploy again) |
| 422 | ValidationError |
A container count or window out of bounds (min_containers 0 to 5, max_containers 1 to 10, scaledown_window 2 to 3600), or a field update does not take |
| 502 | ServerError |
The live deployment refused an update and nothing changed; retry (the SDK retries once) |
| - | PollTimeoutError |
wait_until_active passed timeout; the deployment keeps provisioning |
Calling the endpoint: Endpoint errors. Streams: Stream errors.