# CourtListener → Opinion & Docket Markdown (`ingenious_quip_bxq/courtlistener-markdown`) Actor

CourtListener opinions, dockets, and search → Markdown due-diligence / RAG cards + JSON. Keyless search by default; optional buyer CourtListener API token for /opinions/ and /dockets/. No PACER login. Failed rows free. 256 MB.

- **URL**: https://apify.com/ingenious_quip_bxq/courtlistener-markdown.md
- **Developed by:** [新世紀書僮](https://apify.com/ingenious_quip_bxq) (community)
- **Categories:** Business, Developer tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 1,000 courtlistener cards

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## CourtListener → Opinion & Docket Markdown

Turn **CourtListener** opinions, dockets, and search hits into Markdown due-diligence / RAG cards + JSON.

**CourtListener REST API only** (`https://www.courtlistener.com/api/rest/v4/`). **No PACER username/password, no PACER wallet, no paywall scraping.**

### Modes

| Path | Endpoint | Token |
|---|---|---|
| **Default / keyless** | `GET /search/?q={query}&type=o` (or `type=d`) | None |
| **Opinion / docket BYOK** | `GET /opinions/{id}/`, `/dockets/{id}/`, `/clusters/{id}/` | Your CourtListener API token as `Authorization: Token <token>` |

`mode=auto` (default): `queries` → search; `opinionIds` / `docketIds` / parsed `urls` → authenticated detail (requires `apiToken`).

#### Get a CourtListener API token (buyer self-serve)

1. Create a free account at https://www.courtlistener.com/register/
2. Open **https://www.courtlistener.com/profile/api-token/**
3. Copy the token into this Actor’s `apiToken` input (secret)

Header format (CourtListener uses Django REST **Token**, not Bearer):

```
Authorization: Token YOUR_TOKEN
```

The Actor publisher does **not** store a shared team token, does **not** perform any KYC / top-up, and never asks for PACER credentials.

### Input

- `queries` — string list (keyless search)
- `opinionIds` / `docketIds` — ids or API URLs (need `apiToken`)
- `urls` — CourtListener opinion / docket / API URLs (site `/opinion/{id}/` uses **cluster** id)
- `datasetId` / `keyValueStoreId` + `keyValueRecordKey` (default `INPUT_COURT`) / `idField`
- `mode` — `auto` | `search` | `opinion` | `docket`
- `apiToken` — optional secret
- `enrichSearchHits` (default true) — with token, deepen opinion search hits via `/opinions/{id}/`
- `includeRagChunks` (default true)
- `snippetMaxChars` 4000 · `searchPageSize` 5 · `maxItems` 50 · `maxConcurrency` 2 · `maxRetries` 3 · `requestTimeoutSecs` 30

### Output

Dataset row per card: `kind` (`opinion` | `docket` | `search_hit`), `id`, `caseName`, `court`, `dateFiled` / `dateArgued`, `citation`, `snippet` / `excerpt`, `absoluteUrl`, `markdown`, `source`, `status`, error fields.

Key-value store: `REPORT.md`, `CHUNKS.jsonl`, `SUMMARY`, `OUTPUT`.

Markdown sections: **Identity · Court & Dates · Summary/Excerpt · Citations · Source**.

### Pricing (pay-per-event)

| Event | Price |
|---|---|
| `apify-actor-start` | $0.001 |
| `court-card` (primary) | **$0.003** per successful card |

Invalid input, not found, auth errors, rate limits after retries, and other failures are **free**.

### Example

```json
{
  "queries": ["Miranda v. Arizona"],
  "mode": "auto",
  "apiToken": "YOUR_TOKEN",
  "includeRagChunks": true,
  "maxItems": 5,
  "snippetMaxChars": 4000
}
```

### Limits

Default run: **256 MB**, timeout **3600 s** (max memory 1024 MB). Keep concurrency low on the keyless path.

### Licence

Actor source is AGPL-3.0. CourtListener data is provided by Free Law Project; respect their terms and rate limits.

### Source code

Open source (AGPL-3.0): https://github.com/xbox002000/courtlistener-markdown

# Changelog

This Actor's version history is a separate document: https://apify.com/ingenious_quip_bxq/courtlistener-markdown/changelog.md

# Actor input Schema

## `queries` (type: `array`):

Free-text CourtListener search queries (keyless). Uses GET /api/rest/v4/search/. One card per hit (capped by maxItems / searchPageSize).

## `opinionIds` (type: `array`):

CourtListener opinion IDs (integers) or /api/rest/v4/opinions/{id}/ URLs. Requires apiToken. Site /opinion/{id}/ URLs use cluster ids — prefer urls field or paste the cluster URL there.

## `docketIds` (type: `array`):

CourtListener docket IDs or /docket/{id}/ / /api/rest/v4/dockets/{id}/ URLs. Requires apiToken.

## `urls` (type: `array`):

Opinion, docket, or API URLs, e.g. https://www.courtlistener.com/opinion/8976604/miranda-v-arizona/ (cluster id) or /docket/{id}/…. Opinion/docket detail fetches require apiToken.

## `datasetId` (type: `string`):

Optional. Read queries/ids/urls from another run's dataset (field from 'ID field', else query / opinionId / docketId / url / id).

## `keyValueStoreId` (type: `string`):

Optional. Read from a KV record: JSON {queries, opinionIds, docketIds, urls}, array, or plain text lines.

## `keyValueRecordKey` (type: `string`):

Record key inside the key-value store.

## `idField` (type: `string`):

Optional. Field name holding the query, id, or URL in dataset items or JSON objects.

## `mode` (type: `string`):

auto = detect from dedicated fields (queries→search, opinionIds→opinion, docketIds→docket, urls parsed). search = force search type=o (or type=d only if you only pass docket-oriented queries via mode… use docket mode for docket search). opinion / docket force those authenticated endpoints when ids are given.

## `apiToken` (type: `string`):

Optional. Your free CourtListener API token from https://www.courtlistener.com/profile/api-token/ (sent as Authorization: Token <token>). Not required for search. Stored encrypted, never logged. Placeholders like YOUR_TOKEN are ignored. Publisher does not store a shared token. Never put PACER passwords here.

## `stopOnAuthError` (type: `boolean`):

After CourtListener returns 401/403 once on a token call, skip further authenticated endpoints. Search still works. Failed rows are free.

## `enrichSearchHits` (type: `boolean`):

If apiToken is set, deepen each opinion search hit by fetching /opinions/{id}/ for fuller plain_text. Extra authenticated calls; respect rate limits.

## `includeRagChunks` (type: `boolean`):

Write one self-describing chunk per card section to KV record CHUNKS.jsonl.

## `snippetMaxChars` (type: `integer`):

Truncate opinion plain_text / HTML excerpt in Markdown to this many characters (note appended when truncated).

## `searchPageSize` (type: `integer`):

How many search hits to request per query (further capped by maxItems).

## `maxItems` (type: `integer`):

Stop after this many successful cards (0 = no limit). Also caps the number of input targets processed.

## `maxConcurrency` (type: `integer`):

Parallel lookups. CourtListener rate-limits anonymous and free-token traffic; 2 is a safe default.

## `maxRetries` (type: `integer`):

Retries for HTTP 429 (honours Retry-After, capped at 30 s), 5xx, timeouts and network errors. 400/401/403/404 are not retried.

## `requestTimeoutSecs` (type: `integer`):

Timeout for each CourtListener HTTP call.

## Actor input object example

```json
{
  "queries": [
    "Miranda v. Arizona"
  ],
  "keyValueRecordKey": "INPUT_COURT",
  "mode": "auto",
  "stopOnAuthError": true,
  "enrichSearchHits": true,
  "includeRagChunks": true,
  "snippetMaxChars": 4000,
  "searchPageSize": 5,
  "maxItems": 50,
  "maxConcurrency": 2,
  "maxRetries": 3,
  "requestTimeoutSecs": 30
}
```

# Actor output Schema

## `results` (type: `string`):

Dataset items: kind, id, caseName, court, dates, citation, excerpt, markdown, source, errorClass.

## `reportMarkdown` (type: `string`):

Due-diligence cards: Identity · Court & Dates · Summary/Excerpt · Citations · Source.

## `chunks` (type: `string`):

One JSON line per card section with kind / caseName / section / text, ready to embed.

## `summary` (type: `string`):

cardsOk, cardsFailed, byClass, bySource, byKind, charged, durationSecs, peakMemoryMb.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "queries": [
        "Miranda v. Arizona"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("ingenious_quip_bxq/courtlistener-markdown").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "queries": ["Miranda v. Arizona"] }

# Run the Actor and wait for it to finish
run = client.actor("ingenious_quip_bxq/courtlistener-markdown").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "queries": [
    "Miranda v. Arizona"
  ]
}' |
apify call ingenious_quip_bxq/courtlistener-markdown --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,ingenious_quip_bxq/courtlistener-markdown"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/l20iteY4v1aDN04AL/builds/S1opnthA3NPgjTCdP/openapi.json
