Apilyn DocsDeveloper portal

Apilyn sandbox Quickstart

This guide exercises the public /v1 API in local development or a sandbox environment. It uses fake/dev credentials and a small PDF fixture, so it is safe to run repeatedly.

Prerequisites

  • Python/uv, Node, PostgreSQL, Redis and object storage from the repository dev

setup.

  • The API running locally with the Compose services from .env.example:
make setup
docker compose --env-file .env.example up -d postgres redis minio
make migrate
make seed-plans
(
  cd backend
  APP_ENV=development uv run uvicorn apilyn.main:app --host 127.0.0.1 --port 8000
)

In another shell:

export APILYN_API_URL="${APILYN_API_URL:-http://127.0.0.1:8000}"
export APILYN_SUBJECT="quickstart-owner"
export APILYN_EMAIL="quickstart@example.com"
export APILYN_IDP_SECRET="dev-only-fake-idp-secret-value!!"

Local development uses the fake IdP. The snippet below creates a bearer token compatible with that provider:

export APILYN_ACCESS_TOKEN="$(
  cd backend && uv run python - <<'PY'
from apilyn.auth.fake import FakeIdentityProvider

provider = FakeIdentityProvider(
    issuer="https://idp.apilyn.test",
    audience="apilyn-api",
    secret="dev-only-fake-idp-secret-value!!",
)
print(provider.issue_token(subject="quickstart-owner", email="quickstart@example.com"))
PY
)"

1. Create a sandbox organization

export APILYN_ORG_ID="$(
  curl -sS -X POST "$APILYN_API_URL/v1/orgs" \
    -H "Authorization: Bearer $APILYN_ACCESS_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{"name":"Quickstart Org","slug":"quickstart-org","plan_code":"free","data_region":"eu"}' \
  | python -c 'import json,sys; print(json.load(sys.stdin)["id"])'
)"
echo "$APILYN_ORG_ID"

If you have already created the org slug, change the slug or reuse an existing organization ID.

2. Create a sandbox API key

The API key endpoints require an authenticated owner/admin context. The returned secret is shown once; save it as APILYN_API_KEY.

export APILYN_API_KEY="$(
  curl -sS -X POST "$APILYN_API_URL/v1/api-keys" \
    -H "Authorization: Bearer $APILYN_ACCESS_TOKEN" \
    -H "X-Org-Id: $APILYN_ORG_ID" \
    -H "Content-Type: application/json" \
    -d '{"environment":"sandbox","scopes":["jobs:read","jobs:create"]}' \
  | python -c 'import json,sys; print(json.load(sys.stdin)["secret"])'
)"

Use Authorization: Bearer $APILYN_API_KEY for the remaining API calls.

3. Prepare a fake PDF fixture

printf '%s\n' '%PDF-1.4' '% Apilyn quickstart fake PDF fixture' '%%EOF' > /tmp/apilyn-quickstart.pdf
export APILYN_FIXTURE_BYTES="$(wc -c < /tmp/apilyn-quickstart.pdf | tr -d ' ')"

4. Create an upload intent

export APILYN_UPLOAD_JSON="$(
  curl -sS -X POST "$APILYN_API_URL/v1/uploads" \
    -H "Authorization: Bearer $APILYN_API_KEY" \
    -H "X-Org-Id: $APILYN_ORG_ID" \
    -H "Content-Type: application/json" \
    -d "{\"filename\":\"apilyn-quickstart.pdf\",\"content_type\":\"application/pdf\",\"content_length\":$APILYN_FIXTURE_BYTES}"
)"
export APILYN_UPLOAD_ID="$(python -c 'import json,os; print(json.loads(os.environ["APILYN_UPLOAD_JSON"])["id"])')"
export APILYN_UPLOAD_URL="$(python -c 'import json,os; print(json.loads(os.environ["APILYN_UPLOAD_JSON"])["upload_url"])')"
echo "$APILYN_UPLOAD_ID"

Upload the bytes to the returned MinIO/S3 presigned URL:

curl -sS -X PUT "$APILYN_UPLOAD_URL" \
  -H "Content-Type: application/pdf" \
  --data-binary @/tmp/apilyn-quickstart.pdf

5. Complete intake

curl -sS -X POST "$APILYN_API_URL/v1/uploads/$APILYN_UPLOAD_ID/complete" \
  -H "Authorization: Bearer $APILYN_API_KEY" \
  -H "X-Org-Id: $APILYN_ORG_ID"

If fake storage was not populated, this returns a stable error envelope. Populate the fake storage from a TestClient fixture or run the API with MinIO/S3 for a fully curl-only local flow.

6. Create an idempotent job

export APILYN_IDEMPOTENCY_KEY="quickstart-merge-$(date +%s)"
export APILYN_JOB_ID="$(
  curl -sS -X POST "$APILYN_API_URL/v1/jobs" \
    -H "Authorization: Bearer $APILYN_API_KEY" \
    -H "X-Org-Id: $APILYN_ORG_ID" \
    -H "Idempotency-Key: $APILYN_IDEMPOTENCY_KEY" \
    -H "Content-Type: application/json" \
    -d "{\"pipeline\":\"pdf.merge\",\"pipeline_version\":\"1\",\"inputs\":{\"files\":[{\"upload_id\":\"$APILYN_UPLOAD_ID\"}]},\"parameters\":{}}" \
  | python -c 'import json,sys; print(json.load(sys.stdin)["id"])'
)"
echo "$APILYN_JOB_ID"

Reusing the same Idempotency-Key with the same body returns the same job. Reusing it with a different body returns 409 idempotency_conflict.

7. Poll until terminal

for _ in $(seq 1 15); do
  body="$(curl -sS "$APILYN_API_URL/v1/jobs/$APILYN_JOB_ID" \
    -H "Authorization: Bearer $APILYN_API_KEY" \
    -H "X-Org-Id: $APILYN_ORG_ID")"
  status="$(python -c 'import json,sys; print(json.load(sys.stdin)["status"])' <<< "$body")"
  echo "job status: $status"
  case "$status" in
    completed|failed|cancelled) break ;;
  esac
  sleep 1
done

If no worker is running, the job may remain queued; that still verifies create and poll. Start the worker runtime for the target pool when you want the job to reach completed.

8. Download a retained fixture

Completed jobs expose output upload IDs in output_refs. The upload created in this guide is also retained and can be used to verify the download flow:

export APILYN_OUTPUT_UPLOAD_ID="$APILYN_UPLOAD_ID"
export APILYN_DOWNLOAD_URL="$(
  curl -sS "$APILYN_API_URL/v1/uploads/$APILYN_OUTPUT_UPLOAD_ID/download" \
    -H "Authorization: Bearer $APILYN_API_KEY" \
    -H "X-Org-Id: $APILYN_ORG_ID" \
  | python -c 'import json,sys; print(json.load(sys.stdin)["download_url"])'
)"
curl -sS "$APILYN_DOWNLOAD_URL" -o /tmp/apilyn-output.pdf

If you intentionally run the API with STORAGE_BACKEND=fake, use the generated SDK smoke tests as the executable fake-storage fixture:

make sdk-smoke

Next steps

  • Recipes (sync vs async, idempotency, errors): RECIPES.md
  • Webhook signing: WEBHOOKS.md
  • Error code catalog: ERROR_CODES.md
  • Offline SDK samples: sdk/samples/ (see sdk/samples/README.md)

Contract and SDK checks

make openapi
make openapi-check
make openapi-lint
make openapi-diff
make sdk
make sdk-smoke

The generated clients are under sdk/generated/python and sdk/generated/typescript; both include GENERATED_FROM with the OpenAPI SHA-256 used to produce them.