# Troubleshoot API requests

Identify the type of failure before changing a credential or retrying. Record only the status, method, path without
private query values, UTC time, and `X-Request-ID`. Do not expose an authorization header, token, API key,
request/response body, cursor, contact value, message content, or provider data in a prompt, log, screenshot, issue,
or support message.

Compare observed behavior with the [generated OpenAPI contract](https://themochi.app/docs/api/openapi.json) before changing a request.

## Start with these checks

1. Confirm the canonical docs and OpenAPI contract are reachable and describe the operation.
2. Confirm the expected organization, connection method, scope, and any required member role or rollout approval.
3. Use the HTTP status as the main category. Use a typed error value when present. Do not make decisions from human
   wording.
4. Apply only the current [Errors](https://themochi.app/docs/api/troubleshooting-and-safety/errors), [Rate limits](https://themochi.app/docs/api/troubleshooting-and-safety/rate-limits), and [Idempotency](https://themochi.app/docs/api/troubleshooting-and-safety/idempotency) rules.
5. After a correction, make the smallest safe read or verification request. Do not broaden scopes or expose a credential to “debug” it.

## `401`: the connection is not accepted

The credential is missing, malformed, expired, invalid, revoked, or unavailable. For CLI browser approval, inspect
`mochi auth status` and follow the current CLI error code. Do not read its credential storage. For an API key, ask
the operator to check the secret-manager setting and key status without printing the value. For MCP, use the
existing reconnect screen only when that connection is invalid. Do not export its token.

Repeated `401` responses are not retryable until the authentication cause changes.

## `403`: the connection lacks permission

Mochi accepted the connection, but it lacks a required permission or role. Compare the current OpenAPI scope with
the approved task. If the permission was intentionally omitted, stop and request a separate, limited approval. A
required member role or organization-principal identity cannot be bypassed by repeating the request.

If the issue is controlled self-serve key access, check [Create and manage an API key](https://themochi.app/docs/api/start-here/manage-api-keys). A
missing Developers menu means Mochi has not enabled the path for that exact organization; a direct URL cannot bypass
the rollout.

If this is an MCP connection, read [Already connected through MCP?](https://themochi.app/docs/api/common-tasks/already-connected-mcp). Do not export the
token: an MCP grant does not by itself authorize a Public API `/v1/` operation.

Never solve `403` by borrowing another person's credential or asking for a broader token in a prompt.

## `404`: the resource or feature is unavailable

The resource may not exist, may belong to another organization, or may not be enabled. Mochi intentionally does not
reveal whether another organization's resource exists. Recheck only non-secret IDs and availability. Do not try
nearby IDs or assume the problem is authentication.

## `409`: another request or state conflicts

For a write that supports safe retries, the same request may still be running. Follow [Retry writes
safely](https://themochi.app/docs/api/troubleshooting-and-safety/idempotency) and preserve the key, method, path, and body. For a state conflict such as an overwrite,
read the current resource and stop the write sequence. Get a new approved plan before changing it.

## `429`: too many requests

Wait for the current `Retry-After` value. Add a small random delay when workers share a key. Limit attempts and the
number of requests running at once. Do not rotate credentials to evade a limit. Staying under the API limit does not
guarantee that Mochi will accept an outbound message.

## Network or `5xx` failure

For a read, retry a limited number of times and wait longer after each failure. For a write, first check whether the
current documentation defines a safe retry. If the provider or application result is unknown, do not invent a new
idempotency key. If the contract does not define safe behavior, stop and ask for help with sanitized request details.

## Ask for support safely

Provide support with:

- documentation/OpenAPI version or URL;
- UTC timestamp;
- HTTP method and sanitized path;
- status and typed error code, if present;
- `X-Request-ID`;
- connection method, organization identifier, and non-secret key or connection label; and
- what safe verification was attempted.

If a credential may have been exposed, stop using it, remove the exposed copy where possible, and ask the operator to revoke or rotate it through the supported UI. Do not include the credential itself in the incident record.
