API recipes
Companion to QUICKSTART.md. These recipes assume a sandbox API key (sk_test_…) and X-Org-Id. Full curl bootstrap lives in the quickstart.
Executable samples (Python/TypeScript) live under sdk/samples/.
Async job: upload → complete → create → poll → download
POST /v1/uploads— receiveid+upload_url(never a storage key).PUTbytes toupload_urlwith returned headers.POST /v1/uploads/{id}/complete— intake/malware gate; status becomes
ready_for_processing (or rejection with a storage/intake error.code).
POST /v1/jobswithIdempotency-Keyandinputs.upload_ids.- Poll
GET /v1/jobs/{job_id}until terminal:
completed | failed | cancelled | expired.
GET /v1/jobs/{job_id}/outputs/{alias}/download— signed URL for the artifact.
Job lifecycle: queued → running → completed|failed|cancelled|expired.
Sync tool vs async job
| Sync tool | Async job | |
|---|---|---|
| Endpoint | POST /v1/tools/{tool_name} | POST /v1/jobs |
| Body | { "parameters": { … } } | pipeline + upload inputs |
| Response | 200 with output immediately | 202 job id; poll for artifacts |
| Use when | Structured/text ops (JSON, CSV, GEO, …) | Files / OCR / Office / web capture / AI docs |
List both surfaces via GET /v1/operations?execution_mode=sync_tool|async_job.
Example sync call:
curl -sS -X POST "$APILYN_API_URL/v1/tools/json.format" \
-H "Authorization: Bearer $APILYN_API_KEY" \
-H "X-Org-Id: $APILYN_ORG_ID" \
-H "Content-Type: application/json" \
-d '{"parameters":{"text":"{\"b\":1,\"a\":2}","indent":2,"sort_keys":true}}'
Idempotency
- Required header on
POST /v1/jobs:Idempotency-Key(≤128 chars). - Same key + same payload fingerprint → replay (
200with existing job). - Same key + different payload →
409witherror.code=idempotency_conflict. - Keys are scoped per organization.
Webhook signing
See WEBHOOKS.md. Summary:
- Headers:
X-Apilyn-Signature,X-Apilyn-Timestamp,X-Apilyn-Event-Id,
X-Apilyn-Event-Type
- Signature format:
t=<unix>,v1=<hmac_sha256_hex> - Signed payload:
"{timestamp}." + raw_body(raw body is canonical JSON)
Error handling
Always parse:
{ "error": { "code": "…", "message": "…", "details": {}, "request_id": "…" } }
Catalog: ERROR_CODES.md.
Contract freeze checks
make openapi-check
make openapi-lint
make openapi-diff
make sdk-check
make sdk-smoke