> 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/technical-reference/apis-and-mcp/request-validation-and-error-responses.md).

# Request Validation and Error Responses

Public APIs validate requests before performing supported operations. Read the status and error body together to decide whether to correct the request or retry.

![Check status and body before retrying](https://1957915746-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQ1Sgy933krTyK0S4JpP%2Fuploads%2FJF45pPQP1BMpQR9AOeFv%2Frequest-validation-and-error-responses.png?alt=media)

Illustrative backend control flow. Implement the named handlers for your application. Correct rejected inputs or access before retrying; an uncertain run-start response must not trigger a blind second POST.

<details>

<summary>Copy the example</summary>

```python
response = session.post(
    f"{base_url}/v2/runs", json=run_request
)
if response.status_code in (400, 422):
    inspect_validation_error(response.json())
elif response.status_code == 401:
    check_credential()
elif response.status_code == 403:
    check_scope_and_resource_access()
else:
    response.raise_for_status()
    track_created_run(response.json())
```

</details>

## Before you begin

The endpoint schema and a way to retain request and run identifiers without logging secrets.

## Key concepts

| Term              | Definition                                                                                                                                                  |
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Validation        | A check against supported structure and constraints. Passing validation does not prove that generated answers meet every quality requirement.               |
| Schema            | A definition of fields, types, required values, and supported constraints. Use it to validate the shape of data; it does not establish factual correctness. |
| HTTP status       | The numeric outcome returned for an HTTP request. Read the response body too; accepted work can still be running.                                           |
| Revision conflict | A response indicating that the resource changed since the version used for an edit. Read current state and reconcile changes before resubmitting.           |
| Reconciliation    | Checking the run or destination to determine whether an uncertain operation completed. Do this before retrying a write after a timeout.                     |

## Handle an invalid API request

1. Validate required fields, types, and allowed values before sending.
2. Inspect non-success responses and preserve their error details.
3. Correct input or access problems before retrying; reconcile uncertain writes first.

The client reports a useful error and avoids repeating invalid or ambiguous operations.

## Behavior and limitations

A 2xx response can mean accepted work rather than completed work. A timeout or server error can occur after work starts. Error formats vary by API version. Do not treat every non-success response as a temporary outage or discard the response body.

| Condition                               | Next action                                                        |
| --------------------------------------- | ------------------------------------------------------------------ |
| Invalid or missing credential           | Correct authentication before repeating the request.               |
| Insufficient access                     | Check key scope, organization, and resource sharing.               |
| Invalid input                           | Correct the reported field using the operation’s schema.           |
| State or revision conflict              | Read current state and decide whether the operation still applies. |
| Provider rate limit                     | Follow the provider’s retry guidance and reduce request pressure.  |
| Timeout or server failure after a write | Check the run or destination before submitting the write again.    |

## Related resources

[API Versions and Compatibility](https://docs.stackai.com/technical-reference/apis-and-mcp/api-versions-and-compatibility.md)


---

# 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/technical-reference/apis-and-mcp/request-validation-and-error-responses.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.
