For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DocsAPI ReferenceSDKs
DocsAPI ReferenceSDKs
      • Overview
      • Chat Completions
      • Prompt Templates
      • Files & Batches
      • Embeddings
      • Image Generation
      • Responses (Reasoning)
      • Compare (Multi-model)
      • Models
      • Error Handling
LogoLogo
On this page
  • Error Handling
  • Retry and backoff
  • Streaming failure recovery
Python SDK

Error Handling

||View as Markdown|
Was this page helpful?
Edit this page
Previous

Models

Next

Node.js SDK Overview

Built with

Error Handling

1from meshapi import MeshAPIError
2
3try:
4 client.chat.completions.create(params)
5except MeshAPIError as e:
6 print(f"[{e.status}] {e.error_code}: {e}")
7 print("Request ID:", e.request_id)
8
9 if e.error_code == "rate_limit_exceeded":
10 print(f"Retry after {e.retry_after_seconds}s")
11 elif e.error_code == "spend_limit_exceeded":
12 print("Account balance exhausted. Top up to continue.")
13 elif e.error_code == "unauthorized":
14 print("Invalid API key.")
15 elif e.error_code == "model_not_found":
16 print("Model not supported.")
17 elif e.error_code == "upstream_error":
18 print("Provider error:", e.provider_error)
19 elif e.error_code == "validation_error":
20 print("Invalid request:", e.details)
CodeHTTPMeaning
unauthorized401Invalid or missing key
forbidden403Key suspended
not_found / model_not_found404Resource or model not found
spend_limit_exceeded402Account balance at zero. Top up to continue.
validation_error / unprocessable_entity422Bad request body
rate_limit_exceeded429RPM or RPD limit hit
upstream_error / gateway_timeout / internal_error500Upstream or server error
parse_errorn/aSDK could not parse response body
stream_interruptedn/aMid-stream connection dropped

Mid-stream errors (sent as SSE frames before [DONE]) raise the same MeshAPIError from inside the iterator.

Retry and backoff

The client automatically retries GET and non-streaming POST / PATCH requests on status codes 429, 502, 503, 504 with exponential backoff (default: 3 retries, base delay 500 ms, max 30 s, with jitter). The Retry-After header is respected on 429 responses.

1client = MeshAPI(
2 base_url="https://api.meshapi.ai",
3 token="rsk_...",
4 max_retries=5, # 0 to disable
5 timeout=30.0,
6)

Streaming failure recovery

Streams do not retry. If a connection drops mid-stream, a MeshAPIError with error_code="stream_interrupted" is raised. Catch it and restart a new request:

1try:
2 for chunk in client.chat.completions.stream(params):
3 process(chunk)
4except MeshAPIError as e:
5 if e.error_code == "stream_interrupted":
6 # restart from scratch
7 ...