> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rhetoric.law/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart (agent)

This guide sets up an integration where an AI agent, rather than a human in a
browser, drives the filing through a filing session. It follows the same shape
as the [quickstart](/guides/quickstart): create a filer, create a session, then
hand the session off, but the handoff is to an agent instead of to a frontend
component.

In broad strokes, this is the process:

* Create an API key
* Install the API client on your backend
* Create a filer and a filing session
* Hand the agent the session token, the skill file, and a document
* Listen for filing events

## Create an API key

You use API keys to authenticate requests to the Rhetoric API. Create one from
the [dashboard](https://dashboard.rhetoric.law/). Each key is scoped to an
environment: `live` or `test`. Filings submitted using a test key do not get
sent to a real court. Use a test key while you build out your integration.

Treat API keys like passwords. Keep them on your backend, and do not commit them
to source control or expose them to the browser or an agent.

## Install the API client on your backend

The Rhetoric API client is a TypeScript package that exposes all of the
operations provided by our API. It is meant to be used on your backend. You
can install it using the following command:

```shell theme={null}
npm install @rhetoriclabs/rhetoric
```

Once the package is installed, create a client like so:

```ts theme={null}
import { RhetoricClient } from "@rhetoriclabs/rhetoric";

const client = new RhetoricClient({
  url: "https://api.rhetoric.law",
  token: process.env.RHETORIC_API_KEY,
});
```

## Create a filer

A filer represents an entity that files documents through Rhetoric, such as an
individual or an organization. A filer typically corresponds one to one with a
user of your platform.

Call [create filer](/api-reference/filers/create-filer) on the backend the
first time a user of your platform needs to file something, and associate the
returned filer ID with your user. On subsequent filings for the same user,
reuse that ID rather than creating a new filer.

```ts theme={null}
const { filer } = await client.createFiler({});
```

## Create a filing session

A filing session holds the state of an in-progress filing. An agent can read
and advance that session through the API. Call [create filing
session](/api-reference/filing-sessions/create-filing-session) with the ID
of the filer conducting the filing.

```ts theme={null}
const { session, sessionToken } = await client.createFilingSession({
  filerId: filer.id,
});
```

This operation returns a `sessionToken`. It authenticates the two operations an
agent uses to drive the session, is scoped to this session only, and is only
returned once at creation time. It cannot be recovered later, so capture it
before handing it off.

## Hand the session to an agent

Unlike your API key, which should stay on your backend, a session token is
scoped to a single filing session and is safe to hand to whatever drives that
session: in this case, an agent. Give the agent three things:

1. The `sessionToken` from the previous step.
2. A pointer to the skill file at
   [`docs.rhetoric.law/.well-known/skills/filing-session/skill.md`](https://docs.rhetoric.law/.well-known/skills/filing-session/skill.md),
   which tells it how to call `resume-filing-session` and
   `apply-filing-session-event` to read and advance the form.
3. Whatever documents the filing requires, so it can attach them when it
   reaches the appropriate step, and so that it can extract the relevant
   information.

How you hand these pieces of information off depends on your agent framework; it
might be done as a tool call, as part of its initial prompt, or however else it
consumes instructions and files. Where a human filer would read the rendered
Element and respond to it, the agent instead resumes the session, reads the
returned form, and applies events to fill fields, upload documents, and trigger
actions, repeating until the form is driven to submission.

You can try this out yourself before wiring up a real agent. Point an agent at
a test session and walk it through a test filing using a demo account:

<Steps>
  <Step title="Select a court system">
    Choose <strong>California</strong>.
  </Step>

  <Step title="Select court">
    Choose <strong>Santa Cruz - Civil</strong>.
  </Step>

  <Step title="Log in">
    Log in using our test account. The username is{" "}
    <strong>[mustafa+prose-demo@rhetoric.law](mailto:mustafa+prose-demo@rhetoric.law)</strong> and the password is{" "}
    <strong>Hellorhetoric1</strong>.
  </Step>

  <Step title="Choose a filing type">
    Choose <strong>New case</strong>.
  </Step>

  <Step title="Select case category">
    Choose <strong>Civil - Unlimited</strong>.
  </Step>

  <Step title="Select case type">
    Choose <strong>Breach of Contract/Warranty</strong>.
  </Step>

  <Step title="Add parties">
    This filing requires two parties. Add <strong>Mustafa Moiz</strong> as a
    plaintiff, and add <strong>Hamza Surti</strong> as a defendant. For each
    party, set the party kind to <strong>Individual</strong>. Mustafa Moiz
    should be designated as the filer.
  </Step>

  <Step title="Add a filing entry">
    Add a filing entry with the filing code <strong>Complaint</strong>. Add a
    document to the entry with the document type <strong>Public</strong>. Have
    the agent attach this [sample complaint](/assets/sample-complaint.pdf) as a
    placeholder. It has one page.
  </Step>

  <Step title="Select a payment account">
    Use our test payment method, listed as <strong>Credit card</strong>.
  </Step>

  <Step title="Review fees">
    The fee review step shows the total cost of filing as well as the line items
    that contribute to that cost.
  </Step>

  <Step title="Disclaimers">
    Check the box to agree to the <strong>eService Agreement</strong>.
  </Step>

  <Step title="Review and submit">
    The final review step shows a summary of the filing, including the routing
    info, parties, documents, and payment account. Confirm that the selections
    match the guidance above, then trigger the submit action to submit the
    filing.
  </Step>
</Steps>

## Listen for the submission webhook

When the agent completes the session, Rhetoric sends a [filing
submitted](/api-reference/webhooks/filing-submitted) event to any webhook you
have registered. Register a webhook endpoint from the
[dashboard](https://dashboard.rhetoric.law/) to be notified, rather than
polling the API for status changes. See the [webhooks](/guides/webhooks) guide
for details on registering endpoints, retries, and idempotency, and the
[webhooks reference](/api-reference/webhooks/filing-submitted) for the events
Rhetoric can send.

## Next steps

If you want a deeper understanding of the domain, our [filing
primer](/guides/primer/overview) provides a high level overview of the efiling
system and the core concepts involved. For detailed information about the
endpoints Rhetoric offers and the patterns we follow, see the [API
reference](/api-reference/introduction). For the contract an agent uses to
drive a session, see the [Filing session skill
file](https://docs.rhetoric.law/.well-known/skills/filing-session/skill.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.