Run a Function in real time
curl --request POST \
--url https://your-sutro-deployment.example.com/v1/functions/{name}/run \
--header 'Authorization: <authorization>' \
--header 'Content-Type: <content-type>' \
--data '{
"input": {}
}'import requests
url = "https://your-sutro-deployment.example.com/v1/functions/{name}/run"
payload = { "input": {} }
headers = {
"Authorization": "<authorization>",
"Content-Type": "<content-type>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': '<content-type>'},
body: JSON.stringify({input: {}})
};
fetch('https://your-sutro-deployment.example.com/v1/functions/{name}/run', 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://your-sutro-deployment.example.com/v1/functions/{name}/run",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'input' => [
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: <content-type>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://your-sutro-deployment.example.com/v1/functions/{name}/run"
payload := strings.NewReader("{\n \"input\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "<content-type>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://your-sutro-deployment.example.com/v1/functions/{name}/run")
.header("Authorization", "<authorization>")
.header("Content-Type", "<content-type>")
.body("{\n \"input\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://your-sutro-deployment.example.com/v1/functions/{name}/run")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = '<content-type>'
request.body = "{\n \"input\": {}\n}"
response = http.request(request)
puts response.read_body{
"request_id": "<string>",
"function": {},
"output": {},
"confidence": 123,
"usage": {}
}API
Run a Function in real time
Execute a published Function on one input and wait for the answer.
POST
/
v1
/
functions
/
{name}
/
run
Run a Function in real time
curl --request POST \
--url https://your-sutro-deployment.example.com/v1/functions/{name}/run \
--header 'Authorization: <authorization>' \
--header 'Content-Type: <content-type>' \
--data '{
"input": {}
}'import requests
url = "https://your-sutro-deployment.example.com/v1/functions/{name}/run"
payload = { "input": {} }
headers = {
"Authorization": "<authorization>",
"Content-Type": "<content-type>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': '<content-type>'},
body: JSON.stringify({input: {}})
};
fetch('https://your-sutro-deployment.example.com/v1/functions/{name}/run', 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://your-sutro-deployment.example.com/v1/functions/{name}/run",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'input' => [
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: <content-type>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://your-sutro-deployment.example.com/v1/functions/{name}/run"
payload := strings.NewReader("{\n \"input\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "<content-type>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://your-sutro-deployment.example.com/v1/functions/{name}/run")
.header("Authorization", "<authorization>")
.header("Content-Type", "<content-type>")
.body("{\n \"input\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://your-sutro-deployment.example.com/v1/functions/{name}/run")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = '<content-type>'
request.body = "{\n \"input\": {}\n}"
response = http.request(request)
puts response.read_body{
"request_id": "<string>",
"function": {},
"output": {},
"confidence": 123,
"usage": {}
}Run a published Function on a single input. Hosted providers return the answer
with HTTP
Any other field returns
Real-time calls accept PNG, JPEG, and WebP images up to 5 MiB each and hosted
PDFs up to 20 MiB each. Native Qwen3.5 and Gemma 4 real-time Functions accept
unencrypted PDFs up to 32 MiB each when the deployment advertises that support.
Native PDFs are rendered on the server into page images with extracted text
and page numbers, using the same representation as Batch. A row is limited to
eight images total: each PDF page and each separate image counts once. Inputs
exceeding that limit or the model’s context window are rejected, not truncated.
Native Batch ingestion has a separate
20 MiB image limit for HTTPS URLs or raw image data URI strings. SDK image
uploads and Harmonize dataset or Function collection images remain limited to
5 MiB each, including review reimports. Use HTTPS URLs for larger Batch images.
Encrypted PDFs and XFA forms are unsupported; export XFA forms to standard PDFs
first. Documents exceeding preprocessing resource limits, including one million
extracted characters per PDF, are rejected without truncation.
The bytes are sniffed, so a declared
Send
Handle it as you would that status: for example, retry a
Some HTTP clients return an unparseable body as a string instead of raising;
axios does by default. Check that the body has
Every successful answer is also recorded in the Function’s Monitoring
tab.
Deployment operators can change hosted defaults with
Requests are never retried automatically: a Function run can incur inference
costs, and a caller waiting on an answer should decide for itself whether to try
again.
The Python SDK wraps this endpoint as
200; native sidecar Functions return HTTP 202 and an authenticated
polling path. The Function supplies its optimized prompt, model, output schema, and
sampling defaults; none of them can be overridden per request. Use
Batch instead for tables of inputs.
Configure your deployment URL and API key before
using the examples below. Use the deployment where you published the Function.
Headers
Body
The Function’s input fields. Keys must match the Function’s configured inputs; every field is required and unknown fields are rejected. Values that are not strings are converted the same way Batch converts a row:
null becomes an empty string, objects and lists become JSON, and anything else becomes its plain string form. A bare string is accepted in place of the object when the Function has exactly one text input. Image and PDF fields take an asset value.422 invalid_input. A confidence_scoring field sent by
older clients is accepted and ignored.
Run a published Function
curl --fail-with-body "${SUTRO_API_URL%/}/v1/functions/support-escalation/run" \
-H "Authorization: Key $SUTRO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": {"text": "The customer reports an unrecognized charge."}
}'
Image and PDF inputs
An image or PDF input field takes one of three values.| Value | Shape |
|---|---|
| Inline bytes | {"base64": "...", "mime_type": "image/png"} |
| URL | {"url": "https://..."}. https only, public hosts only (no private, loopback, or link-local addresses), streamed with a 10 second timeout. |
| Stored asset | {"name": "march-invoice.pdf"}, or the name as a bare string. |
curl --fail-with-body "${SUTRO_API_URL%/}/v1/functions/invoice-reader/run" \
-H "Authorization: Key $SUTRO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": {
"note": "check page 2",
"scan": {"base64": "JVBERi0...", "mime_type": "application/pdf"},
"logo": {"url": "https://cdn.example.com/logo.png"},
"prior": {"name": "march-invoice.pdf"}
}
}'
type or mime_type that disagrees with
the actual content is rejected rather than passed to the model. Inline base64
counts toward the 48 MiB request-body limit; use an HTTPS URL or stored asset
for larger PDFs.
Native acceptance, polling, and cancellation
A native sidecar Function returns HTTP202 with a run handle:
{
"request_id": "rt_5d0c2f1e8a4b4c9e9f1a2b3c4d5e6f70",
"state": "pending",
"poll_path": "/v1/functions/support-escalation/runs/rt_5d0c2f1e8a4b4c9e9f1a2b3c4d5e6f70",
"deadline_seconds": 1800,
"retry_after_seconds": 1
}
GET to the returned poll_path on the same deployment with the original
API key. Wait the Retry-After interval between polls. HTTP 202 means the run
is still pending; HTTP 200 returns the completed response. A terminal failure
returns its ordinary error status and body. Polling does not repeat inference
or charge the request rate limit again.
# Set this to the request_id returned by POST.
REQUEST_ID="rt_5d0c2f1e8a4b4c9e9f1a2b3c4d5e6f70"
RUN_URL="${SUTRO_API_URL%/}/v1/functions/support-escalation/runs/$REQUEST_ID"
curl -i "$RUN_URL" -H "Authorization: Key $SUTRO_API_KEY"
# Cancel a pending run when its result is no longer needed.
curl -X DELETE "$RUN_URL" -H "Authorization: Key $SUTRO_API_KEY"
DELETE returns HTTP 202 while cancellation is pending, or HTTP 200 once
the run is terminal. Polling a cancelled run returns 409 cancelled. Unknown
run IDs and runs owned by another key or Function return 404 request_not_found.
The original deadline defaults to 1,800 seconds and includes worker startup;
polling does not extend it. Interrupted runs return 503 interrupted without
replaying inference. Hosted Functions keep their existing synchronous behavior.
The Python SDK handles this protocol
automatically while run_function() waits for the answer.
Runs longer than 85 seconds
A hosted run can take up to 240 seconds. A run still going at 85 seconds starts its response early: HTTP200, a space every 15 seconds while the
Function runs, then the usual JSON body. JSON parsers skip the leading spaces,
so no client change is needed. Allow a total timeout of at least 240 seconds
and a read timeout above 85 seconds.
Once the 200 is sent, the status can no longer change. A run that fails
after that point ends the body with a line of text instead of JSON, so your
JSON parser raises rather than returning an answer. The line starts with
Sutro error, then the status the failure would otherwise have had, its
code, and the request_id:
Sutro error 504 timeout rt_01j7wnq3f8k2c9x4: 'support-escalation' did not complete within 240 seconds. This run failed after its 200 response had started, so the status could not change. See https://docs.sutro.sh/reference/api/run-function#runs-longer-than-85-seconds
504 or 502.
Treat any 200 whose body does not parse as JSON as a failure. A deployment
restart during a long run can end the body after the spaces, with no error line.
response = requests.post(url, json=body, headers=headers, timeout=(10, 300))
response.raise_for_status()
try:
result = response.json()
except ValueError:
# "Sutro error 504 timeout rt_...: ..." or, rarely, only spaces.
raise RuntimeError(response.text.strip() or "empty response") from None
output before using it.
Completed response
{
"request_id": "rt_01j7wnq3f8k2c9x4",
"function": {
"name": "support-escalation",
"model": "claude-sonnet-4-5",
"model_source": "model-sweep"
},
"output": {"label": "billing", "reasoning": "..."},
"confidence": 1.0,
"usage": {"input_tokens": 412, "output_tokens": 38, "cost_usd": 0.0016}
}
This request’s ID. It also appears in the Function’s Monitoring tab and in every error body, for log and support lookups.
The Function that answered: its
name, the base model, and model_source. model_source is model-sweep when a model was set active from a model sweep, or sutro-default when the Function ran its latest iteration’s prompt on the Sutro default model.The answer, parsed against the Function’s output schema. A string when the Function has no schema.
Deprecated and always
1.0. Sutro no longer computes a confidence score; the field stays at 1.0 so existing integrations keep working, and will be removed in a future release.Provider-reported
input_tokens and output_tokens, plus estimated provider
cost_usd when pricing is available, for the whole request.Limits
| Limit | Default |
|---|---|
| Requests per API key | 10 per second, bursting to 20 |
| In-flight requests per model | 64 per deployment |
| Hosted request timeout | 240 seconds; responses start early after 85 seconds (details) |
| Native request deadline, including worker startup | 1,800 seconds |
| Input size | 200,000 characters, counted after the input fields are joined into the prompt the model receives |
| Real-time asset size | Images: 5 MiB each; hosted PDFs: 20 MiB each; native PDFs: 32 MiB each |
| Native media per row | Eight images total, including every rendered PDF page |
| Request body | 48 MiB |
HARMONIZE_REALTIME_*,
except the 240-second run timeout.
Native deadlines use HARMONIZE_NATIVE_FUNCTION_TIMEOUT_SECONDS; aggregate
pending inputs default to 64 MiB with HARMONIZE_NATIVE_FUNCTION_PENDING_BYTES.
Errors
Failures return{"detail": ..., "code": ..., "request_id": ...}. A 429 or
503 that can be retried carries a Retry-After header with the number of
seconds to wait. A run that fails after its response started at 85 seconds
ends a 200 body with an error line instead; see
Runs longer than 85 seconds.
| Status | code | Cause |
|---|---|---|
| 401 | unauthorized | Missing or invalid API key. |
| 404 | function_not_found | No Function by that name in this deployment. |
| 404 | request_not_found | The native run does not exist or does not belong to this key and Function. |
| 409 | cancelled | The native run was cancelled. |
| 409 | no_runnable_prompt | The Function has no published or completed prompt to run yet. |
| 409 | deployment_unpublished | The latest deploy or completed iteration failed to publish to Batch, so real time refuses to serve a prompt Batch does not. Retry the publish. |
| 413 | payload_too_large | The request body is over 48 MiB. |
| 422 | invalid_input | Malformed body, a field other than input (or the ignored confidence_scoring), missing, unknown, or oversized input, or an unreadable asset. |
| 422 | not_servable | The Function’s active model cannot serve it in real time. The message says why. |
| 429 | rate_limited | Your key’s request rate. See Retry-After. |
| 429 | at_capacity | The deployment has no room for another request on this model right now. Retry after Retry-After. |
| 429 | provider_rate_limited | The model provider rate limited the request. See Retry-After. |
| 502 | provider_error | The model provider failed or returned an unusable answer. |
| 503 | auth_unavailable | The deployment could not verify the API key. Retry. |
| 503 | interrupted | The native run’s process stopped; inference is not replayed. |
| 503 | provider_not_configured | No API key is configured for the Function’s provider. Add one in the app’s provider settings. |
| 503 | inference_spend_circuit_open | The deployment’s paid-inference budget is paused. See Retry-After. |
| 504 | timeout | A native run exceeded its deadline. A hosted run that reaches its 240-second deadline reports timeout in its error line instead. |
run_function().