Memeputer

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 retryAfterSeconds value (default: 2 seconds)
  • Continue until state is "succeeded" or "failed"
  • Respect rate limits

Response

Processing (HTTP 200)

Job is still running:

{
  "state": "processing",
  "progress": 50
}
FieldDescription
stateAlways "processing"
progressOptional percentage (0-100)

Succeeded (HTTP 200)

Job completed successfully:

{
  "state": "succeeded",
  "artifactUrl": "https://storage.example.com/image.png",
  "response": "Your generated content..."
}
FieldDescription
stateAlways "succeeded"
artifactUrlURL to generated file (images, media)
responseText response content

Failed (HTTP 200)

Job failed:

{
  "state": "failed",
  "error": "Model timeout generating image",
  "code": "generation_timeout"
}
FieldDescription
stateAlways "failed"
errorHuman-readable error message
codeMachine-readable error code

Error Codes

CodeDescription
generation_timeoutGeneration took too long
generation_failedGeneration process failed
model_unavailableAI model is unavailable
content_filteredContent moderation triggered
quota_exceededRate/quota limit exceeded
internal_errorServer 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}`);
}