Metadata-Version: 2.4
Name: jibayai
Version: 0.1.0
Summary: Official-style Python SDK for the JibayAI API
Author: JibayAI
License-Expression: MIT
Project-URL: Homepage, https://jibay.ir/
Project-URL: Documentation, https://platform.jibay.ir/docs/
Keywords: jibayai,jibay,ai,chat,image,music,video,sdk
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests<3,>=2.31
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: twine>=5; extra == "dev"
Requires-Dist: pytest>=8; extra == "dev"
Dynamic: license-file

# JibayAI Python SDK

A small, validated Python client for the JibayAI chat, image, music and video APIs.

## Installation

```bash
pip install jibayai
```

## Quick start

```python
from jibayai import JibayAI

client = JibayAI(api_key="YOUR_API_KEY")

result = client.chat(
    "Hello, how are you?",
    model="jibay-5",
)
print(result)
```

You may keep the key outside source code:

```bash
export JIBAYAI_API_KEY="YOUR_API_KEY"
```

```python
from jibayai import JibayAI

client = JibayAI()
print(client.chat("سلام"))
```

## Direct functions

For small scripts, the four operations are also available directly on the package:

```python
import jibayai

result = jibayai.chat(
    "Hello",
    api_key="YOUR_API_KEY",
    model="jibay-5",
)

image_result = jibayai.image("A futuristic city", api_key="YOUR_API_KEY")
music_result = jibayai.music("Calm jazz", api_key="YOUR_API_KEY")
video_result = jibayai.video("Autumn forest", api_key="YOUR_API_KEY")
```

For repeated calls, prefer one `JibayAI` client so its HTTP connection is reused.

## Chat

```python
result = client.chat(
    text="Latest AI news",
    model="jibay-5",
    system="Answer clearly and briefly.",
    chats=[
        {"role": "user", "text": "My name is Ali"},
        {"role": "assistant", "text": "Nice to meet you"},
    ],
    search_web=True,
    signal=False,
    saved_memories={"language": "fa"},
    mode_official=False,
)
```

The documented chat request uses JSON. To support the previous form-encoded integration:

```python
client = JibayAI(api_key="YOUR_API_KEY", chat_encoding="form")
# Or only for one request:
result = client.chat("Hello", encoding="form")
```

## Image

The API requires a numeric `device`. The SDK generates one automatically when omitted.

```python
result = client.image("A futuristic city at night")
# Or:
result = client.image("A futuristic city at night", device=12345)
print(result)
```

## Music

```python
result = client.music("Calm Persian jazz")
print(result)
```

## Video

```python
result = client.video("An autumn forest with cinematic camera movement")
print(result)
```

## Download generated media

Generated media links are temporary, so save the result promptly:

```python
saved_path = client.download(
    "https://example.com/temporary-file.mp4",
    "outputs/video.mp4",
)
print(saved_path)
```

## Validation

The SDK validates API key, text, booleans, chat history, device ID, timeout, retry count, URLs and model identifier syntax before sending a request.

By default, new model names are allowed when their syntax is valid. Enable strict model validation when you need an allow-list:

```python
client = JibayAI(
    api_key="YOUR_API_KEY",
    strict_models=True,
    supported_models=["jibay-4", "jibay-4.1", "jibay-5"],
)
```

## Error handling

```python
from jibayai import (
    JibayAI,
    JibayError,
    ValidationError,
    AuthenticationError,
    RateLimitError,
    TimeoutError,
    NetworkError,
    ServerError,
)

client = JibayAI(api_key="YOUR_API_KEY")

try:
    result = client.chat("Hello", model="jibay-5")
except ValidationError as exc:
    print("Bad parameter:", exc.parameter, exc)
except AuthenticationError:
    print("Check the API key")
except RateLimitError as exc:
    print("Rate limited; retry after:", exc.retry_after)
except TimeoutError:
    print("Request timed out")
except NetworkError:
    print("Network connection failed")
except ServerError as exc:
    print("JibayAI server error:", exc.status_code)
except JibayError as exc:
    print("Other SDK error:", exc)
```

## Built-in help

```python
print(client.help())
print(client.help("chat"))
print(client.help("errors"))
```

## Command line

```bash
export JIBAYAI_API_KEY="YOUR_API_KEY"

jibayai chat "Hello" --model jibay-5
jibayai image "A futuristic city"
jibayai music "Calm jazz"
jibayai video "Autumn forest"
jibayai help errors
```

Use `jibayai --help` and `jibayai <command> --help` for all parameters.

## Local development and test

```bash
python -m pip install -e .
python -m unittest discover -s tests -v
```

## Build

```bash
python -m pip install --upgrade build twine
python -m build
python -m twine check dist/*
```

## Publish to TestPyPI

```bash
python -m twine upload --repository testpypi dist/*
```

## Publish to PyPI

```bash
python -m twine upload dist/*
```

When Twine asks for credentials, use `__token__` as the username and your complete `pypi-...` token as the password.
