← Back to Dashboard

Code Samples

Working examples in Python, cURL, and JavaScript.

Generate 100 W-2 Documents

# Create the job
JOB_ID=$(curl -s -X POST https://symagedocs.ai/api/v1/generate \
  -H "Authorization: Bearer $SYMAGEDOCS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{{"form_id": "irs_w2_2025", "quantity": 100, "output_formats": ["pdf_typed", "json"]}}' \
  | jq -r '.data.job_id')

# Poll until complete
while true; do
  STATUS=$(curl -s "https://symagedocs.ai/api/v1/jobs/$JOB_ID" \
    -H "Authorization: Bearer $SYMAGEDOCS_API_KEY" | jq -r '.data.status')
  echo "Status: $STATUS"
  [ "$STATUS" = "completed" ] && break
  [ "$STATUS" = "failed" ] && echo "FAILED" && exit 1
  sleep 5
done

# Download
curl -o w2_documents.zip \
  "https://symagedocs.ai/api/v1/jobs/$JOB_ID/download/pdf_typed" \
  -H "Authorization: Bearer $SYMAGEDOCS_API_KEY"
import time, httpx

API_KEY = "sk_live_YOUR_KEY"
BASE = "https://symagedocs.ai/api/v1"
H = {{"Authorization": f"Bearer {{API_KEY}}"}}

# Create job
resp = httpx.post(f"{{BASE}}/generate", headers=H, json={{
    "form_id": "irs_w2_2025", "quantity": 100,
    "output_formats": ["pdf_typed", "json"],
}})
job_id = resp.json()["data"]["job_id"]
print(f"Job: {{job_id}}")

# Poll
while True:
    s = httpx.get(f"{{BASE}}/jobs/{{job_id}}", headers=H).json()["data"]
    print(f"{{s['status']}} ({{s['progress']*100:.0f}}%)")
    if s["status"] == "completed": break
    if s["status"] == "failed": raise Exception(s["error"])
    time.sleep(5)

# Download
pdf = httpx.get(f"{{BASE}}/jobs/{{job_id}}/download/pdf_typed", headers=H)
open("w2_documents.zip", "wb").write(pdf.content)
const API_KEY = "sk_live_YOUR_KEY";
const BASE = "https://symagedocs.ai/api/v1";
const H = {{ "Authorization": `Bearer ${{API_KEY}}`, "Content-Type": "application/json" }};

// Create job
const createResp = await fetch(`${{BASE}}/generate`, {{
  method: "POST", headers: H,
  body: JSON.stringify({{
    form_id: "irs_w2_2025", quantity: 100,
    output_formats: ["pdf_typed", "json"],
  }}),
}});
const {{ data: {{ job_id }} }} = await createResp.json();

// Poll
while (true) {{
  const {{ data }} = await (await fetch(`${{BASE}}/jobs/${{job_id}}`, {{ headers: H }})).json();
  console.log(`${{data.status}} (${{(data.progress*100).toFixed(0)}}%)`);
  if (data.status === "completed") break;
  if (data.status === "failed") throw new Error(data.error);
  await new Promise(r => setTimeout(r, 5000));
}}

// Download
const pdf = await fetch(`${{BASE}}/jobs/${{job_id}}/download/pdf_typed`, {{ headers: H }});
require("fs").writeFileSync("w2_documents.zip", Buffer.from(await pdf.arrayBuffer()));

Generate a Tabular Dataset

# Parse description into schema
COLS=$(curl -s -X POST https://symagedocs.ai/api/v1/tabular/parse \
  -H "Authorization: Bearer $SYMAGEDOCS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{{"prompt": "employee name, department, hire date, salary"}}' \
  | jq '.data.columns')

# Generate 5,000 rows
JOB_ID=$(curl -s -X POST https://symagedocs.ai/api/v1/tabular/generate \
  -H "Authorization: Bearer $SYMAGEDOCS_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{{\"columns\": $COLS, \"quantity\": 5000, \"output_formats\": [\"csv\"]}}" \
  | jq -r '.data.job_id')

sleep 10
curl -o employees.csv \
  "https://symagedocs.ai/api/v1/tabular/$JOB_ID/download/csv" \
  -H "Authorization: Bearer $SYMAGEDOCS_API_KEY"
import time, httpx

API_KEY = "sk_live_YOUR_KEY"
BASE = "https://symagedocs.ai/api/v1"
H = {{"Authorization": f"Bearer {{API_KEY}}"}}

# Parse NL into schema
cols = httpx.post(f"{{BASE}}/tabular/parse", headers=H,
    json={{"prompt": "employee name, department, hire date, salary"}}
).json()["data"]["columns"]
print(f"Parsed {{len(cols)}} columns")

# Generate
job_id = httpx.post(f"{{BASE}}/tabular/generate", headers=H,
    json={{"columns": cols, "quantity": 5000, "output_formats": ["csv"]}}
).json()["data"]["job_id"]

# Poll
while True:
    s = httpx.get(f"{{BASE}}/tabular/{{job_id}}/status", headers=H).json()["data"]
    print(f"{{s['percent']}}% ({{s['rows_generated']}}/{{s['total_rows']}})")
    if s["status"] == "completed": break
    time.sleep(2)

# Download
csv = httpx.get(f"{{BASE}}/tabular/{{job_id}}/download/csv", headers=H)
open("employees.csv", "wb").write(csv.content)

Generate Raw Identities

curl -X POST https://symagedocs.ai/api/v1/identities \
  -H "Authorization: Bearer $SYMAGEDOCS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{{"quantity": 5, "seed": 42}}' | jq '.data[0]'
import httpx

resp = httpx.post("https://symagedocs.ai/api/v1/identities",
    headers={{"Authorization": f"Bearer {{API_KEY}}"}},
    json={{"quantity": 5, "seed": 42}})

for p in resp.json()["data"]:
    print(f"{{p['first_name']}} {{p['last_name']}}, age {{p['age_years']}}")
const resp = await fetch("https://symagedocs.ai/api/v1/identities", {{
  method: "POST",
  headers: {{ "Authorization": `Bearer ${{API_KEY}}`, "Content-Type": "application/json" }},
  body: JSON.stringify({{ quantity: 5, seed: 42 }}),
}});
const {{ data }} = await resp.json();
data.forEach(p => console.log(`${{p.first_name}} ${{p.last_name}}, age ${{p.age_years}}`));