> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.emtelligent.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.emtelligent.com/_mcp/server.

# Quickstart Code Example

This page submits one document with a prompt, waits for the job to finish, and
prints the summary. It uses only the `requests` library.

Create an API key with the `summarization:process` scope on the
[emtelligent platform](/platform/api-keys), then set it in the environment:

```bash
pip install requests
export SUMMARIZATION_API_KEY='...'
```

## Create a session

Authenticate with the `Authorization: Bearer` header, using an API key or an
[OAuth 2.0 access token](/platform/oauth-clients).

```python
import os
import time

import requests

BASE = "https://summarize.emtelligent.com"

session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['SUMMARIZATION_API_KEY']}"
```

## Submit a job

The prompt says what the summary is for. The `Idempotency-Key` makes the
submission safe to retry: sending the same key and body again returns the
original job instead of creating, and charging for, a second one.

```python
document = (
    "DISCHARGE SUMMARY\n"
    "Admitted with community-acquired pneumonia, right lower lobe. Treated with "
    "ceftriaxone and azithromycin, switched to oral amoxicillin on day 3. "
    "Background: type 2 diabetes on metformin; hypertension on lisinopril.\n"
    "Discharged home on day 4. Follow up with the GP in one week; repeat chest "
    "X-ray in six weeks.\n"
)

response = session.post(
    f"{BASE}/v1/jobs",
    headers={"Idempotency-Key": "discharge-0001"},
    json={
        "document": {"text": document},
        "prompt": "Summarize the admission and the follow-up plan for the patient's GP, "
                  "in under 100 words.",
    },
)
response.raise_for_status()
job_id = response.json()["id"]
```

## Wait for it to finish

```python
while True:
    job = session.get(f"{BASE}/v1/jobs/{job_id}").json()
    if job["status"] not in ("queued", "running"):
        break
    time.sleep(2)

if job["status"] != "succeeded":
    raise SystemExit(f"job {job['status']}: {job.get('error')}")
```

## Read the summary

The result can be downloaded **once**; store it if you need it again.

```python
result = session.get(f"{BASE}/v1/jobs/{job_id}/result").json()
print(result["summary"])                  # Markdown
print(result["stats"]["billed_pages"], "pages billed")
```

The summary is Markdown generated from your document. Render it with a
sanitizing Markdown renderer — see [Result format](/summarization/reference/result-format).

## Several documents

To summarize several of a patient's documents as one, send `documents` instead of
`document`. The summary cites them as `[1]`, `[2]`, …, and `references` maps each
number to your document's `id`:

```python
response = session.post(
    f"{BASE}/v1/jobs",
    json={
        "documents": [
            {"id": "discharge", "text": document, "chart_date": "2026-09-14"},
            {"id": "gp-visit", "chart_date": "2026-09-22",
             "text": "GP review: cough settling, afebrile. Metformin continued."},
        ],
        "prompt": "Summarize the illness and its follow-up for a respiratory referral.",
    },
)
response.raise_for_status()
```

Poll and download it the same way, then:

```python
for ref in result.get("references", []):
    print(f"[{ref['ref']}] = {ref['document']}")
for warning in result.get("warnings", []):
    print("warning:", warning["code"], warning.get("documents"))
```

See [Several documents](/summarization/guides/several-documents).