Agent
Agent errors
A request that is refused is an HTTP error and costs nothing. A run that started and could not finish is not an error; its status says how it ended.
Copy as MarkdownOpen in ChatGPT (opens in a new tab)Open in Claude (opens in a new tab)
There are two kinds of trouble, and they look different.
- The request is refused.
POST /v1/agentanswers with an HTTP error in the one error shape every endpoint uses. No run exists, nothing is held and nothing is charged. - The run ends early. The start answered
202, the run exists, and it endedincomplete,failedorcancelled. That is not an HTTP error:GET /v1/agent/{id}answers200, andstatusandstop_reasonsay what happened.
Requests that are refused
| Status and code | When | What to do |
|---|---|---|
400 INVALID_PARAM | A field the API does not take; no prompt, or one outside 3 to 4,000 characters; a schema that is not an object schema with properties; a model or processor that is not on the list; a value of the wrong type or out of range | Fix the request. message names the field |
400 INVALID_PARAM with details.plan_max_credits | max_credits is above your plan's per-run cap (Free 200, Starter 1,000, Growth 2,500, Scale 5,000, Business 10,000, Enterprise by agreement). The message names the cap; details has max_credits as sent and plan_max_credits, the cap | Send a cap at or under details.plan_max_credits, or leave it out |
400 INVALID_PARAM with details.min_max_credits | max_credits is under what the chosen tier needs to write an answer at all | Send at least details.min_max_credits, or choose a cheaper tier |
400 UNSUPPORTED_OPTION | The tier needs a cap your plan's per-run cap cannot reach. details has model, min_max_credits and plan_max_credits | Choose another tier, or a plan with a higher per-run cap |
401 AUTH_MISSING_KEY, 401 AUTH_INVALID_KEY | No Authorization header, or a key that is malformed, revoked or expired | Send a valid key |
404 JOB_NOT_FOUND | No run with that id for your team. Another team's run is answered the same way | Check the id |
404 SPACE_NOT_FOUND | The space named at the start is not a Space you can use | Check the slug, or leave space out |
409 IDEMPOTENCY_CONFLICT | The Idempotency-Key was already used, in the last 24 hours, with a different body | Use a new key for a new request. To retry, send the same bytes |
429 INSUFFICIENT_CREDITS | Your credits do not cover max_credits, which is held when a run starts | Lower max_credits, or add credits |
429 RATE_LIMITED | 3 runs are already going for your team; or 2 event streams are already open; or polls are coming too fast | Wait retry_after_seconds. For runs, wait for one to end. For streams, close one or poll |
429 CAPACITY | Opening an event stream when every stream we offer, across all teams, is in use | Poll GET /v1/agent/{id} instead. The run is not affected |
{
"error": {
"code": "INVALID_PARAM",
"message": "max_credits must be at least 125 for model \"balanced\": less cannot pay for an answer.",
"retry_after_seconds": null,
"details": { "param": "max_credits", "model": "balanced", "min_max_credits": 125 }
},
"request_id": "req_01JD4FAB5P9V2X6Z8B0C"
}A cap above the plan's, on the Free plan:
{
"error": {
"code": "INVALID_PARAM",
"message": "max_credits of 300 is above this plan's per-run cap of 200. Send 200 or less, or leave max_credits out; a plan with a higher cap allows more.",
"retry_after_seconds": null,
"details": { "param": "max_credits", "max_credits": 300, "plan_max_credits": 200 }
},
"request_id": "req_01JD4FAC7R2W4Y6A8C1D"
}Nothing is held for it, and nothing is charged.
In the SDKs, 400 INVALID_PARAM is a ValidationError, 400 UNSUPPORTED_OPTION an UnsupportedOptionError, a 404 a NotFoundError, 429 INSUFFICIENT_CREDITS an InsufficientCreditsError, 429 RATE_LIMITED a RateLimitError and 429 CAPACITY a CapacityError. Each carries details and retry_after_seconds.
Notes:
- The limits on
max_creditsare checked before anything is held. A refused start costs nothing. - A
webhook_idmust be an active endpoint of your team. One that is not, or is not verified yet, is a400 INVALID_PARAM. GET /v1/agent/{id}/resultson a run that is still going is not an error. It answers202with"ready": falseand aRetry-Afterheader.- Runs are kept for 30 days after they end.
- A stream that closes is not an error either. A stream stays open 5 minutes at most. Open it again with
?after=and the lastseqyou saw.
Errors says which errors are worth retrying, for every endpoint.
Runs that end incomplete
An incomplete run ended before it was done. stop_reason says why. It is charged for the work it did, at least 5 credits, and it is not an error: read what it carries.
stop_reason | What happened | What it carries | Try next |
|---|---|---|---|
budget | The next step did not fit in what was left of max_credits | Usually an answer, written from what was read before the cap. It may cover less of the question | Raise max_credits, or use a smaller processor or a cheaper tier |
time | The run reached 10 minutes | No answer | Ask a narrower question, or use a smaller processor |
no_sources | The searches found nothing the run could read | No answer | Widen the scope: fewer include_domains, a smaller remove_top_sites, more sources, an earlier start_date. Or name pages in urls |
no_support | Pages were read, and no statement could be supported by a quote from them | No answer. sources lists what was read, and not_answered may say what was missing | Rephrase the question to what pages state outright, or widen the scope |
no_answer | The model would not, or could not, write an answer in a form that can be checked | No answer. sources lists what was read | Run it again. If it repeats, rephrase the question |
A run that ended on budget with an answer is still held to the same checks: every statement in it has a quote.
A run that ends completed can still say that one check was not made. On standard and pro, verified: false means the second pass over the citations could not be afforded, reached or read. The answer is kept, every quote in it was still found in its page, and only the second reading is missing. Run it again, or with a higher max_credits, if you need that pass.
Runs that fail
failed means the run ended with no result and no charge. Whatever was held is handed back. Nearly always the fault is ours: a worker stopped, the model or our own service could not be reached, or the run waited 30 minutes without being started. One case is not ours: a run whose error.code is INSUFFICIENT_CREDITS ended when the team could not cover it. Nothing was charged for that either.
erroron the run has acodeand amessagethat says what we know.stop_reasonstaysnullon a failed run.- A failed run is not started again by us. Start a new one. With an
Idempotency-Key, use a new key: the old key still returns the failed run. - If it keeps happening, send us the run's
idand therequest_idof the start.
Runs that are cancelled
cancelled means you sent DELETE /v1/agent/{id}.
- A run that had not started ends at once and costs nothing.
- A run in progress shows
cancellinguntil its current step stops, and thencancelled. The work done is charged, with no minimum; the rest of the hold is handed back. It carries no answer. - Cancelling a run that has already ended changes nothing. The answer is
200with the run as it is.
Checking a run in code
Treat the four endings differently, and read stop_reason on incomplete:
import os
from millionshort import MillionShort, RateLimitError, ValidationError
client = MillionShort(api_key=os.environ["MILLIONSHORT_API_KEY"])
try:
run = client.start_agent("What changed in Northbridge Transit fares in 2026?", max_credits=60)
except ValidationError as error:
# details says what the limit is: plan_max_credits or min_max_credits
raise SystemExit(f"{error.message} {error.details}")
except RateLimitError as error:
raise SystemExit(f"Too many runs at once. Try again in {error.retry_after_seconds} seconds.")
done = client.wait_agent(run.id)
if done.status == "completed":
print(done.answer)
elif done.status == "incomplete":
print("Ended early:", done.stop_reason)
if done.answer:
print(done.answer)
elif done.status == "failed":
# nothing was charged; the run id and the start's request id are what to send us
print("Failed:", done.error["message"], run.id, run.request_id)
else:
print("Cancelled.")
print(done.usage.credits)import { MillionShort, RateLimitError, ValidationError } from 'millionshort';
const client = new MillionShort({ apiKey: process.env.MILLIONSHORT_API_KEY });
try {
const run = await client.startAgent('What changed in Northbridge Transit fares in 2026?', { maxCredits: 60 });
const done = await client.waitAgent(run.id);
if (done.status === 'completed') {
console.log(done.answer);
} else if (done.status === 'incomplete') {
console.log('Ended early:', done.stop_reason);
if (done.answer) console.log(done.answer);
} else if (done.status === 'failed') {
// nothing was charged; the run id and the start's request id are what to send us
console.log('Failed:', done.error?.message, run.id, run.requestId);
} else {
console.log('Cancelled.');
}
console.log(done.usage?.credits);
} catch (error) {
if (error instanceof ValidationError) {
// details says what the limit is: plan_max_credits or min_max_credits
console.error(error.message, error.details);
} else if (error instanceof RateLimitError) {
console.error(`Too many runs at once. Try again in ${error.retryAfterSeconds} seconds.`);
} else {
throw error;
}
}