Skip to main content
Mira Network SDK

Mira Network Python SDK

Your Universal Gateway to AI Language Models

PyPI Version Downloads

Format Implementation

License

Build Status

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

Metadata

Release files for mira-network 0.1.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mira-network 0.1.10
File Size Uploaded Provenance Actions
mira_network-0.1.10.tar.gz 10.7 kB Without provenance Details for mira_network-0.1.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mira-network 0.1.10
File Interpreter ABI Platform Actions
mira_network-0.1.10-py3-none-any.whl Python 3 none any Details for mira_network-0.1.10-py3-none-any.whl

Total release size: 19.4 kB

Release files / mira_network-0.1.10.tar.gz

Download URL mira_network-0.1.10.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
36267116c4dc84e36db345f24350b2ccd7f4dff29a429b00aae49b8608dacb3d
BLAKE2b-256 checksum
How to use checksums
0c7cefe888f210f6874541b8679920fd6d396a5fd2540a60eb2fac7e0676f36b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.21.0 CPython/3.10.15 Darwin/24.3.0

Release files / mira_network-0.1.10-py3-none-any.whl

Download URL mira_network-0.1.10-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd47b8cab26777e7a1406d79fe17d38b74864eb30e30124a239803e4dab7add8
BLAKE2b-256 checksum
How to use checksums
877d6cd82416dfabbbbfe54b79de73cc49d404fab55995258fa180a010a7c3ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.21.0 CPython/3.10.15 Darwin/24.3.0

Security for mira-network 0.1.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page