> For the complete documentation index, see [llms.txt](https://docs.stackai.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stackai.com/stackai-api/stackai-api-developer-guide/requests-responses-pagination-and-retries.md).

# Requests, responses, pagination, and retries

#### JSON and multipart

Use `Content-Type: application/json` for JSON bodies. For uploads, use multipart and let the HTTP client generate the boundary. With curl, `-F 'file=@document.pdf'` is appropriate; do not combine it with a manually set JSON content type. Skill bundles use **files** (plural), while KB uploads use **file** (singular).

Encode path segments and query values; never concatenate raw user input into a URL. Repeated array query parameters are sent as repeated keys where the endpoint says so. UUID fields must contain actual UUIDs; a project ID or provider slug is not interchangeable with a run, resource, or connection ID.

#### Read the envelope for the endpoint you called

Most v2 single-resource responses put the object in `data`. Cursor responses put items in `data` with `next_cursor` and potentially other cursor fields. Offset responses include their own pagination metadata. Empty success metadata can be omitted. A **204** has no response body: do not call `.json()` on it.

Legacy inference, v1 knowledge bases, and legacy analytics do not all share the v2 envelope. Do not add a universal `response.data` accessor to a client covering every version. Use the exact response schema under each endpoint. v1 KB listing returns an array; v2 KB listing returns an envelope.

#### Pagination is not one global convention

| Family                                                         | Pagination                         | Typical default/maximum    |
| -------------------------------------------------------------- | ---------------------------------- | -------------------------- |
| v2 runs                                                        | `cursor`, `page_size`              | 50 / 1000                  |
| KB collections                                                 | `cursor`, `page_size`, `direction` | 50 / 1000                  |
| KB resources                                                   | `cursor`, `page_size`, `direction` | 50 / 100                   |
| Providers, connections, skills, most eval lists, subscriptions | `offset`, `limit`                  | 0 and 50 / 100             |
| Eval run scores and sampled runs                               | Cursor pagination                  | Read the endpoint's limits |
| Legacy analytics                                               | Zero-based `page`, `page_size`     | 0 and 25                   |
| SCIM                                                           | One-based `startIndex`, `count`    | Protocol-specific          |

Treat cursors as opaque. Keep filters fixed during traversal, URL-encode the cursor, and stop when no next cursor is returned. For offset lists, advance by the items returned and use response totals/has-more information where available. Concurrent changes can affect offset traversals; deduplicate by stable ID if you need a complete export. v1 KB list accepts pagination parameters but returns a bare list without a next-cursor envelope; prefer v2 for new paginated clients rather than inventing a cursor.

#### Retry reads; reconcile writes

Use connection/read timeouts, a total deadline, exponential backoff with jitter, and bounded attempts. Retry transient read failures and 429/503 responses when appropriate, honoring `Retry-After` when present. Stop and fix credentials or permissions for 401/403; fix payloads for 400/422.

Do not automatically retry a run start, action invocation, upload, score creation, or other write after an ambiguous timeout or 500. The operation may already have taken effect, incurred usage, or changed an external system. No general idempotency-key contract is defined here. Persist returned resource IDs, inspect status, and reconcile before deciding to send another write.

For asynchronous operations, preserve `Location` and any `status_url`. Resolve relative URLs against the API origin. Only attach credentials to your trusted API origin; a signed file-download URL is a different request and does not need your StackAI authorization header.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stackai.com/stackai-api/stackai-api-developer-guide/requests-responses-pagination-and-retries.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
