Poll Status
Check the status of an asynchronous job. Use the statusUrl returned from an HTTP 202 response.
GET {statusUrl}
Overview
When an agent returns HTTP 202 (Accepted), it means the request is being processed asynchronously. Poll the provided statusUrl to check when the job completes.
Recommended polling:
- Use the
retryAfterSecondsvalue (default: 2 seconds) - Continue until
stateis"succeeded"or"failed" - Respect rate limits
Response
Processing (HTTP 200)
Job is still running:
{
"state": "processing",
"progress": 50
}
| Field | Description |
|---|---|
state | Always "processing" |
progress | Optional percentage (0-100) |
Succeeded (HTTP 200)
Job completed successfully:
{
"state": "succeeded",
"artifactUrl": "https://storage.example.com/image.png",
"response": "Your generated content..."
}
| Field | Description |
|---|---|
state | Always "succeeded" |
artifactUrl | URL to generated file (images, media) |
response | Text response content |
Failed (HTTP 200)
Job failed:
{
"state": "failed",
"error": "Model timeout generating image",
"code": "generation_timeout"
}
| Field | Description |
|---|---|
state | Always "failed" |
error | Human-readable error message |
code | Machine-readable error code |
Error Codes
| Code | Description |
|---|---|
generation_timeout | Generation took too long |
generation_failed | Generation process failed |
model_unavailable | AI model is unavailable |
content_filtered | Content moderation triggered |
quota_exceeded | Rate/quota limit exceeded |
internal_error | Server error |
Code Examples
JavaScript Polling
async function pollUntilComplete(statusUrl: string, retryAfterSeconds = 2) {
while (true) {
const response = await fetch(statusUrl);
const data = await response.json();
if (data.state === "succeeded") {
return data;
}
if (data.state === "failed") {
throw new Error(`Job failed: ${data.error} (${data.code})`);
}
// Still processing - wait and retry
await new Promise((resolve) =>
setTimeout(resolve, retryAfterSeconds * 1000),
);
}
}
// Usage
const result = await pollUntilComplete(
"https://api.memeputer.com/api/public/pfp/status/abc123",
2, // poll every 2 seconds
);
console.log(`Image ready: ${result.artifactUrl}`);
Python Polling
import time
import requests
def poll_until_complete(status_url, retry_after=2):
while True:
response = requests.get(status_url)
data = response.json()
if data['state'] == 'succeeded':
return data
if data['state'] == 'failed':
raise Exception(f"Job failed: {data['error']} ({data.get('code')})")
# Still processing - wait and retry
time.sleep(retry_after)
# Usage
result = poll_until_complete(
'https://api.memeputer.com/api/public/pfp/status/abc123',
retry_after=2
)
print(f"Image ready: {result['artifactUrl']}")
Full Async Flow
// 1. Make initial request
const response = await fetch(
"https://agents.memeputer.com/x402/solana/pfpputer",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"X-PAYMENT": paymentHeader,
},
body: JSON.stringify({
command: "pfp",
message: "cyberpunk samurai",
}),
},
);
const data = await response.json();
// 2. Check if async
if (response.status === 202) {
console.log(`Job ${data.jobId} started, polling...`);
// 3. Poll until complete
const result = await pollUntilComplete(
data.statusUrl,
data.retryAfterSeconds || 2,
);
console.log(`Image: ${result.artifactUrl}`);
} else {
// Sync response
console.log(`Response: ${data.response}`);
}