Skip to main content

Python SDK for Mira Network API

Project description

Mira Network SDK

Mira Network Python SDK

Your Universal Gateway to AI Language Models

PyPI version License: MIT Build Status Coverage Status Downloads Discord

Mira Client enables seamless integration with multiple language models while providing advanced routing, load balancing, and flow management capabilities.


๐ŸŒŸ What is Mira Network?

Mira Network is your unified interface to the world of AI language models. It provides:

  • ๐Ÿ”„ Smart Model Routing: Route requests across different models
  • โš–๏ธ Load Balancing: Distribute workload across nodes
  • ๐ŸŒŠ Flow Management: Handle request patterns efficiently
  • ๐Ÿ”Œ Universal Integration: Single API for multiple models
  • ๐Ÿ“Š Usage Tracking: Monitor your model usage

Why Mira Network SDK?

Feature Mira SDK Traditional Approach
๐Ÿ”„ Multi-model Support Single unified API Separate APIs per model
โš–๏ธ Load Balancing Built-in Custom implementation
๐ŸŒŠ Flow Control Automatic handling Manual implementation
๐Ÿ“Š Usage Tracking Integrated Custom tracking needed
๐Ÿ›ก๏ธ Error Handling Standardized across models Model-specific handling

๐ŸŽฏ Perfect For

  • ๐Ÿค– AI Applications
  • ๐Ÿ“ Text Generation
  • ๐Ÿ” Search Enhancement
  • ๐ŸŽฎ Interactive Systems

๐Ÿƒ Quick Start

pip install mira-network
from mira_network import MiraClient

async def get_ai_response(prompt):
    async with MiraClient() as client:
        return await client.chat_completions_create(
            model="your-chosen-model",
            messages=[{"role": "user", "content": prompt}]
        )

๐Ÿ—๏ธ Architecture

graph LR
    A[Your App] --> B[Mira SDK]
    B --> C[Load Balancer]
    C --> D[Mira Node 1]
    C --> E[Mira Node 2]
    C --> F[Mira Node N]

โœจ Key Features

  • ๐Ÿ”Œ Simple, intuitive API
  • ๐Ÿ”„ Async-first design
  • ๐ŸŒŠ Streaming support
  • ๐Ÿ” Error handling
  • ๐Ÿ› ๏ธ Customizable nodes
  • ๐Ÿ“Š Usage tracking

๐Ÿ“‘ Table of Contents

๐Ÿ”ง Installation

Install the SDK using pip:

pip install mira-network

๐Ÿš€ Quick Start

Experience the power of Mira Network in just a few lines of code:

from mira_network import MiraClient

async def main():
    # Initialize with your API key
    client = MiraClient(api_key="your-api-key")

    # Get a response from AI
    response = await client.chat_completions_create(
        model="your-chosen-model",
        messages=[
            {"role": "user", "content": "What is the capital of France?"}
        ]
    )

    # Print the AI's response
    print(response["choices"][0]["message"]["content"])

if __name__ == "__main__":
    import asyncio
    asyncio.run(main())

๐Ÿ“ Basic Usage

Having a Conversation

Engage in natural conversations with AI models. The SDK handles the complexities of managing conversation context and model interactions:

response = await client.chat_completions_create(
    model="your-chosen-model",
    messages=[
        {"role": "system", "content": "You are a helpful assistant"},
        {"role": "user", "content": "Hi! Can you help me?"},
    ]
)

Checking Available Models

Explore the diverse range of available AI models:

models = await client.list_models()
print(models)

Checking Your Credits

Monitor your usage and available credits:

credits = await client.get_user_credits()
print(credits)

๐Ÿ”ง Advanced Usage

Streaming Responses

Perfect for real-time applications and interactive experiences:

stream = await client.chat_completions_create(
    model="your-chosen-model",
    messages=[
        {"role": "user", "content": "Write a story"}
    ],
    stream=True
)

async for chunk in stream:
    print(chunk["choices"][0]["delta"]["content"], end="")

Custom Mira Nodes

Integrate your preferred Mira nodes seamlessly:

response = await client.chat_completions_create(
    model="your-model",
    messages=[{"role": "user", "content": "Hello"}],
    mira_node={
        "base_url": "https://custom-node.com",
        "api_key": "node-api-key"
    }
)

API Token Management

Secure and flexible token management for your applications:

# Create new token
new_token = await client.create_api_token(
    {"description": "Production API Key"}
)

# List tokens
tokens = await client.list_api_tokens()

# Delete token
await client.delete_api_token("token-id")

Using as Context Manager

Efficient resource management with context managers:

async with MiraClient(api_key="your-api-key") as client:
    response = await client.chat_completions_create(...)

๐Ÿ“š Reference

Message Structure

Understanding the core message components:

Message:
    role: str       # "system", "user", or "assistant"
    content: str    # The message content

Error Handling

Robust error handling for production applications:

Validation Errors

try:
    response = await client.chat_completions_create(
        model="your-chosen-model",
        messages=[
            {"role": "invalid", "content": "Hello"}  # Invalid role
        ]
    )
except ValueError as e:
    print(f"Validation error: {e}")

Network Errors

try:
    response = await client.chat_completions_create(...)
except httpx.HTTPError as e:
    print(f"HTTP error: {e}")

Environment Configuration

Flexible configuration options for different environments:

import os
from mira_network import MiraClient

client = MiraClient(
    api_key=os.getenv("MIRA_API_KEY"),
    base_url=os.getenv("MIRA_API_URL", "https://apis.mira.network")
)

๐Ÿ’ก Real-world Examples

AI-powered Customer Service

async def handle_customer_query(query: str) -> str:
    async with MiraClient() as client:
        response = await client.chat_completions_create(
            model="your-chosen-model",
            messages=[
                {"role": "system", "content": "You are a helpful customer service agent."},
                {"role": "user", "content": query}
            ],
            temperature=0.7,
            max_tokens=150
        )
        return response.choices[0].message.content

Content Generation Pipeline

async def generate_blog_post(topic: str) -> dict:
    async with MiraClient() as client:
        # Generate outline
        outline = await client.chat_completions_create(...)

        # Generate content
        content = await client.chat_completions_create(...)

        # Generate meta description
        meta = await client.chat_completions_create(...)

        return {"outline": outline, "content": content, "meta": meta}

๐Ÿค Support

For feature requests and bug reports, please visit our Console Feedback.

๐Ÿ‘ฅ Contributing

We welcome contributions! Here's how you can help:

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

๐Ÿ“„ License

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


Built with โค๏ธ by the Mira Network team

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

mira_network-0.1.6.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

mira_network-0.1.6-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file mira_network-0.1.6.tar.gz.

File metadata

  • Download URL: mira_network-0.1.6.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.2 CPython/3.13.1 Darwin/24.2.0

File hashes

Hashes for mira_network-0.1.6.tar.gz
Algorithm Hash digest
SHA256 3b586e3eedabba9b0a18745cd545a6e11c91e5b7100d85c6ff56bd693473516e
MD5 a9a2485594b9f39c65b78a581f0818eb
BLAKE2b-256 6bb227f56086a045ce7cf272e604b1067a7f09b4d0bc9d155b8ae97211f60ab5

See more details on using hashes here.

File details

Details for the file mira_network-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: mira_network-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.2 CPython/3.13.1 Darwin/24.2.0

File hashes

Hashes for mira_network-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9a4a9eaa3bcaa224045d5b68f991e3a52c0d62925a693221e876d5e9ea9eb648
MD5 4d478e3ee89b4464d64f7fc8e2ea1448
BLAKE2b-256 bbed0a4ad3af107479e8d09a948e59711c4733ef4d46362fc30997efa4790726

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