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

# Scheduling

> Defer responses for later retrieval.

export const apiEndpoint = 'api.agentfirst.dev';

## Asynchronous mode

An API call that includes the `mode=async` key-value pair will be satisfied asynchronously:

```shell theme={null}
curl -H "Authorization: Bearer $AGENT_FIRST_TOKEN" \
'https://api.agentfirst.dev/search'\
'?terms=prolonged+fasting'\
'&mode=async'
```

<AccordionGroup>
  <Accordion icon="terminal" title="View AI example">
    ```shell theme={null}
    curl -H "Authorization: Bearer $AGENT_FIRST_TOKEN" \
    'https://api.agentfirst.dev/ai'\
    '?prompt=Summarize+the+latest+research+on+prolonged+fasting.'\
    '&mode=async'
    ```
  </Accordion>

  <Accordion icon="terminal" title="View browser example">
    ```shell theme={null}
    curl -H "Authorization: Bearer $AGENT_FIRST_TOKEN" \
    'https://api.agentfirst.dev/browser'\
    '?url=https://pubmed.ncbi.nlm.nih.gov/?term=prolonged+fasting'\
    '&mode=async'
    ```
  </Accordion>
</AccordionGroup>

In response, the API will provide a JSON job identifier:

```json theme={null}
{ "id": "078fd246-f0f7-44a0-aabb-cadd7b12454f" }
```

The job results, completion, or content or job status can be requested any time thereafter by
passing back the ID:

```shell theme={null}
curl -H "Authorization: Bearer $AGENT_FIRST_TOKEN" \
'https://api.agentfirst.dev/search'\
'?id=078fd246-f0f7-44a0-aabb-cadd7b12454f'
```

<AccordionGroup>
  <Accordion icon="terminal" title="View AI example">
    ```shell theme={null}
    curl -H "Authorization: Bearer $AGENT_FIRST_TOKEN" \
    'https://api.agentfirst.dev/ai'\
    '?id=1851dab8-4619-409f-893f-47dd3a180bc3'
    ```
  </Accordion>

  <Accordion icon="terminal" title="View browser example">
    ```shell theme={null}
    curl -H "Authorization: Bearer $AGENT_FIRST_TOKEN" \
    'https://api.agentfirst.dev/browser'\
    '?id=21cb972e-0e0f-47bb-9ce9-65b99e9cee77'
    ```
  </Accordion>
</AccordionGroup>

The results, completion, or content, if ready, will be returned in the same format as <Link href="search#response-format">synchronous results</Link>, a <Link href="ai#response-format">synchronous completion</Link>, or <Link href="browser#response-format">synchronous content</Link>; otherwise, a JSON status message will be
returned.

A `retrieving` status indicates that the search, conversation, or request is in progress:

```json theme={null}
{ "status": "retrieving" }
```

A `failed` status indicates that the search, conversation, or request was unsuccessful and the call
should be retried:

```json theme={null}
{ "status": "failed" }
```

These are the scheduling request parameters:

| Key    | Required | Value                                                                                                                                                                            |
| :----- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `mode` | ⬜        | The synchronous or asynchronous mode of content retrieval, `sync` or `async`; `sync` is the default mode                                                                         |
| `id`   | ⬜        | The identifier provided by the <Link href="search">search</Link>, <Link href="ai">AI</Link>, or <Link href="browser">browser endpoints</Link> of an asynchronous job to retrieve |

These are the response parameters:

| Key      | Value                                                       |
| :------- | :---------------------------------------------------------- |
| `id`     | The identifier to retrieve an asynchronous job with         |
| `status` | The status of an asynchronous job, `retrieving` or `failed` |
