> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pawa-ai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Async, retries & errors

> Async client, retry configuration, and error handling for the Pawa AI Python SDK.

## Async client

```python theme={null}
import asyncio
from pawa_ai import AsyncPawaAI

async def main():
    async with AsyncPawaAI() as client:
        response = await client.chat.create(
            model="pawa-v1-ember-20240924",
            messages=[
                {
                    "role": "user",
                    "content": [{"type": "text", "text": "Habari yako?"}],
                }
            ],
            stream=False,
        )
        print(response["data"]["request"][0]["message"]["content"])

        stream = await client.chat.create(
            model="pawa-v1-ember-20240924",
            messages=[
                {
                    "role": "user",
                    "content": [{"type": "text", "text": "Explain embeddings briefly."}],
                }
            ],
            stream=True,
        )
        text = await stream.collect_text()
        print(text)

asyncio.run(main())
```

Every sync resource has an async counterpart on `AsyncPawaAI` (`client.models`, `client.voice`, `client.transcribe`, and so on).

## Retries

Retries apply to rate limits (`429`), server errors (`500` / `502` / `503` / `504`), and connection failures. The SDK respects `Retry-After` when present.

```python theme={null}
from pawa_ai import PawaAI, RetryConfig

client = PawaAI(
    retry_config=RetryConfig(
        max_retries=3,
        initial_delay=0.5,
        max_delay=8.0,
        exponential_base=2.0,
        jitter=0.1,
    )
)
```

You can also set `max_retries` on the client constructor for a simpler default.

## Error handling

```python theme={null}
from pawa_ai import (
    PawaAI,
    AuthenticationError,
    RateLimitError,
    BadRequestError,
    NotFoundError,
    APIConnectionError,
)

client = PawaAI()

try:
    client.chat.create(
        model="pawa-v1-ember-20240924",
        messages=[
            {"role": "user", "content": [{"type": "text", "text": "Hello"}]}
        ],
    )
except AuthenticationError as e:
    print(f"Auth failed: {e.message}")
except RateLimitError as e:
    print(f"Rate limited ({e.status_code}): {e.message}")
except BadRequestError as e:
    print(f"Bad request: {e.message}")
except NotFoundError as e:
    print(f"Not found: {e.message}")
except APIConnectionError as e:
    print(f"Connection error: {e}")
```

## Links

* **PyPI:** [https://pypi.org/project/pawa-ai/#description](https://pypi.org/project/pawa-ai/#description)
* **GitHub:** [https://github.com/Sartify/pawa-ai-python](https://github.com/Sartify/pawa-ai-python)
