Python SDK (Beta)

The Python SDK is in beta. It exposes the Collate Prior Auth API as typed Python methods for server-side integrations, background workers, and internal tools that create and monitor authorizations.

The REST API remains the canonical integration surface while the SDK is in beta. Use the Python SDK from backend services, workers, and internal tools. Do not expose API keys in client-side applications.

Install

$python -m venv .venv
$source .venv/bin/activate
$pip install collate-sdk

If your organization does not have SDK beta access, use the REST API guides and API reference instead.

Configure the Client

Set your API key in the environment, then create a client.

$export COLLATE_API_KEY="your-sandbox-api-key"
$export COLLATE_BASE_URL="https://api.sandbox.trycollate.ai"
1import os
2
3from collate import Collate
4
5collate = Collate(
6 api_key=os.environ["COLLATE_API_KEY"],
7 environment=os.environ.get("COLLATE_BASE_URL", "https://api.sandbox.trycollate.ai"),
8)

Pass the key directly only when environment variables are not available:

1collate = Collate(
2 api_key="your-sandbox-api-key",
3 environment="https://api.sandbox.trycollate.ai",
4)

Create an Authorization

Create exactly one authorization for one payer submission. Use a fresh idempotency key for each new create request, and reuse the same key only when retrying the exact same body.

1import uuid
2
3authorization = collate.authorizations.create(
4 provider_npi="1234567893",
5 request={
6 "payer_id": "payer_aetna",
7 "coverage_state": "CA",
8 "request_type": "drug",
9 "service_code": {"system": "hcpcs", "code": "J0791"},
10 },
11 policy={"final_submission": "requires_approval"},
12 metadata={"external_case_id": "case_789"},
13 idempotency_key=str(uuid.uuid4()),
14)
15
16print(authorization.id)
17print(authorization.status)
18print(authorization.next_action.type if authorization.next_action else None)

Resolve Requirements

When status = "requires_action" and next_action.type = "resolve_requirements", patch answers or attach files. Use the current authorization version in If-Match.

1authorization = collate.authorizations.answers.patch(
2 authorization_id=authorization.id,
3 if_match=f'"{authorization.version}"',
4 answers={
5 "item": [
6 {
7 "link_id": "coverage.member_id",
8 "answer": [{"value_string": "W123456789"}],
9 },
10 {
11 "link_id": "request.diagnosis_code",
12 "answer": [{"value_string": "D57.1"}],
13 },
14 ]
15 },
16)

Answer and attachment writes recompute requirements. They do not resume Collate processing by themselves. Call /confirm only when the updated authorization exposes continue_authorization or approve_submission.

Attach a File

The SDK creates and completes the file resource. Upload bytes directly to the single-use URL returned by the API.

1import requests
2
3created = collate.files.create(
4 file_name="clinical-note.pdf",
5 content_type="application/pdf",
6 purpose="authorization_attachment",
7)
8
9with open("clinical-note.pdf", "rb") as file:
10 upload = requests.put(
11 created.upload.url,
12 data=file,
13 headers=created.upload.headers or {},
14 timeout=60,
15 )
16upload.raise_for_status()
17
18file_record = collate.files.complete(file_id=created.file.id)
19
20authorization = collate.authorizations.attachments.create(
21 authorization_id=authorization.id,
22 if_match=f'"{authorization.version}"',
23 file_id=file_record.id,
24 document_types=["clinical_notes"],
25)

Confirm the Current Action

Confirm only confirmable actions.

1from collate import ConfirmAuthorizationBody
2
3request = None
4
5if authorization.next_action and authorization.next_action.type == "approve_submission":
6 request = ConfirmAuthorizationBody(
7 accepted_review_snapshot_id=authorization.submission.review_snapshot.id,
8 )
9
10authorization = collate.authorizations.confirm(
11 authorization_id=authorization.id,
12 if_match=f'"{authorization.version}"',
13 request=request,
14)

After confirmation, Collate usually owns the next step and the authorization returns to processing.

Poll for Changes

1import time
2
3while authorization.status in {"processing", "waiting_on_payer"}:
4 time.sleep(5 if authorization.status == "processing" else 30)
5 authorization = collate.authorizations.retrieve(
6 authorization_id=authorization.id,
7 )
8
9if authorization.status == "requires_action":
10 print("Next action:", authorization.next_action.type)
11elif authorization.status == "completed":
12 print("Outcome:", authorization.outcome)

Async Usage

Use AsyncCollate inside asyncio applications.

1import asyncio
2import os
3
4from collate import AsyncCollate
5
6
7async def main() -> None:
8 collate = AsyncCollate(
9 api_key=os.environ["COLLATE_API_KEY"],
10 environment="https://api.sandbox.trycollate.ai",
11 )
12 authorization = await collate.authorizations.retrieve(
13 authorization_id="auth_123",
14 )
15 print(authorization.status)
16
17
18asyncio.run(main())

Error Handling

The SDK raises ApiError for non-2xx API responses.

1from collate.core.api_error import ApiError
2
3try:
4 authorization = collate.authorizations.retrieve(authorization_id="auth_123")
5except ApiError as error:
6 print(error.status_code)
7 print(error.body)

Use error.body["error"]["code"] for recovery logic when the body is the standard Collate error envelope. Common recoverable codes are version_conflict, review_stale, requirements_not_satisfied, and live_session_not_available.

Method Map

Python method groupCommon methods
authorizationscreate, retrieve, list, confirm, cancel
authorizations.answerspatch
authorizations.attachmentscreate, list, delete
authorization_routeslist, resolve
filescreate, complete, retrieve, download
payers, providerslist, retrieve
authorizations.live_sessionretrieve
authorizations.manual_handoffscreate, retrieve, complete, unable_to_complete, revoke

See the API reference for exact request and response fields.