Skip to main content

Official Python SDK for Reno AI API

Project description

Reno AI SDK

Official Python client library for the Reno AI API.

PyPI version Python Support License: MIT

Features

  • 🚀 Simple and intuitive API
  • 🔄 Streaming support for real-time responses
  • 🛡️ Comprehensive error handling with user-friendly messages
  • 🔁 Automatic retry logic with exponential backoff
  • ⏱️ Configurable timeouts
  • 📝 Full type hints for better IDE support
  • 🧪 Well-tested and production-ready

Installation

pip install renoai

Development Installation

git clone https://github.com/yourusername/renoai-sdk.git
cd renoai-sdk
pip install -e ".[dev]"

Quick Start

from renoai import Reno

# Initialize the client
client = Reno(api_key="reno_sk_your_key_here")

# Simple question
answer = client.ask("What is Python?")
print(answer)

# Chat with message history
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Tell me a joke about programming"}
]
response = client.chat(messages)
print(response.text)

Usage Examples

Basic Usage

from renoai import Reno

# Create client
client = Reno(api_key="reno_sk_xxx")

# Ask a simple question
answer = client.ask("Explain machine learning in simple terms")
print(answer)

# With custom system message
answer = client.ask(
    prompt="What is recursion?",
    system="You are a computer science professor."
)
print(answer)

Chat Completions

# Multi-turn conversation
messages = [
    {"role": "system", "content": "You are a Python expert."},
    {"role": "user", "content": "How do I read a file in Python?"},
    {"role": "assistant", "content": "You can use open() function..."},
    {"role": "user", "content": "What about CSV files?"}
]

response = client.chat(messages, temperature=0.8)
print(response.text)

# Access metadata
print(f"Model: {response.model}")
print(f"Tokens used: {response.usage.total_tokens}")

Streaming Responses

# Stream responses for real-time output
messages = [{"role": "user", "content": "Write a short story"}]

for chunk in client.chat(messages, stream=True):
    if chunk.delta:
        print(chunk.delta, end="", flush=True)

Advanced Configuration

from renoai import Reno

# Custom configuration
client = Reno(
    api_key="reno_sk_xxx",
    base_url="https://api.reno.ai/v1",
    timeout=60,  # 60 second timeout
    max_retries=5  # Retry up to 5 times
)

# Use different model
response = client.chat(
    messages=[{"role": "user", "content": "Hello!"}],
    model="gemma2:9b-instruct",
    temperature=0.9,
    max_tokens=500
)

Error Handling

from renoai import Reno, RenoError, RenoTimeoutError, RenoConnectionError

client = Reno(api_key="reno_sk_xxx")

try:
    response = client.ask("What is AI?")
    print(response)
except RenoTimeoutError as e:
    print(f"Request timed out: {e}")
except RenoConnectionError as e:
    print(f"Connection failed: {e}")
except RenoError as e:
    print(f"API Error [{e.code}]: {e.message}")
    print(e.user_friendly())  # Get user-friendly error message

Context Manager

# Automatically close connection
with Reno(api_key="reno_sk_xxx") as client:
    response = client.ask("Hello!")
    print(response)
# Session automatically closed

API Reference

Reno Client

Reno(
    api_key: str,
    base_url: str = "http://127.0.0.1:8000/api/v1",
    timeout: int = 30,
    max_retries: int = 3
)

Methods

ask(prompt, system=None, model="gemma2:2b-instruct", temperature=0.7, max_tokens=None)

Simple single-turn question. Returns the response text as a string.

chat(messages, model="gemma2:2b-instruct", temperature=0.7, max_tokens=None, stream=False, **kwargs)

Full chat completion with message history. Returns Completion object or generator if streaming.

close()

Close the HTTP session.

Response Objects

Completion

  • text / content: The generated text
  • id: Completion ID
  • model: Model used
  • choices: List of Choice objects
  • usage: Usage object with token counts

Choice

  • content: Message content
  • role: Message role
  • finish_reason: Why generation stopped

Usage

  • prompt_tokens: Tokens in prompt
  • completion_tokens: Tokens in completion
  • total_tokens: Total tokens used

Exceptions

  • RenoError: Base exception for API errors
  • RenoConnectionError: Connection failures
  • RenoTimeoutError: Request timeouts

All exceptions have:

  • code: Error code
  • message: Error message
  • details: Additional details
  • user_friendly(): User-friendly error explanation

Error Codes

The SDK provides detailed error codes for debugging:

  • 1xxx: Authentication errors (invalid/expired API key)
  • 2xxx: Request validation errors (invalid parameters)
  • 3xxx: Model errors (not found, unavailable)
  • 4xxx: Context/token limit errors
  • 5xxx: Rate limiting errors
  • 6xxx: Server errors
  • 7xxx: Content policy violations
  • 8xxx: Billing/payment errors
  • 9xxx: Internal errors

Development

Running Tests

pytest tests/
pytest --cov=renoai tests/  # With coverage

Code Formatting

black renoai/
isort renoai/
flake8 renoai/
mypy renoai/

Building Distribution

python -m build
twine check dist/*

Publishing to PyPI

# Test PyPI
twine upload --repository testpypi dist/*

# Production PyPI
twine upload dist/*

Requirements

  • Python 3.8+
  • requests >= 2.25.0
  • urllib3 >= 1.26.0

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Support

Changelog

0.1.0 (2025-02-15)

  • Initial release
  • Basic chat completions
  • Streaming support
  • Comprehensive error handling
  • Retry logic with exponential backoff

Acknowledgments

Built with ❤️ for the Reno AI community.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

renoai-0.1.0.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

renoai-0.1.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file renoai-0.1.0.tar.gz.

File metadata

  • Download URL: renoai-0.1.0.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for renoai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ce2c254a1c6d46430f28f930529fea0beafd9d6c247efd7d008ee2059ff07207
MD5 9cb34aaefcbc174971354eedef73a2f3
BLAKE2b-256 082eb08633e649a3743f4484c1c1e24302f23bbd9daf623b7c08490243202729

See more details on using hashes here.

File details

Details for the file renoai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: renoai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for renoai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 763dabaae90def35a5498cd865061068ab5320334662f71d0743d900383f0722
MD5 c7634c3cace4269a237f835b01e2c686
BLAKE2b-256 d2ea008b8cef5ccfb40ae4e08eebfec4a20d9b3dec83c4646673e08126ac6520

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page