Skip to main content

Python SDK for Mira Network API

Project description

Mira Network SDK

A Python SDK for interacting with the Mira Network API. This SDK provides both synchronous and asynchronous interfaces to access Mira API endpoints for model inference, API token management, and credit system operations.

Installation

pip install mira-network

Quick Start

Synchronous Usage

from mira_network.sync_client import MiraSyncClient
from mira_network.models import AiRequest, Message

# Using context manager (recommended)
with MiraSyncClient(api_token="your-api-token") as client:  # base_url defaults to https://apis.mira.network/
    # Example 1: Non-streaming response
    request = AiRequest(
        messages=[
            Message(role="system", content="You are a helpful assistant."),
            Message(role="user", content="Hello!")
        ],
        stream=False
    )
    response = client.generate(request)
    print(response)
    
    # Example 2: Streaming response
    stream_request = AiRequest(
        messages=[
            Message(role="system", content="You are a helpful assistant."),
            Message(role="user", content="Tell me a story!")
        ],
        stream=True
    )
    for chunk in client.generate(stream_request):
        print(chunk)

Asynchronous Usage

import asyncio
from mira_network.client import MiraClient
from mira_network.models import AiRequest, Message

async def main():
    # Using async context manager (recommended)
    async with MiraClient(api_token="your-api-token") as client:  # base_url defaults to https://apis.mira.network/
        # Example 1: Non-streaming response
        request = AiRequest(
            messages=[
                Message(role="system", content="You are a helpful assistant."),
                Message(role="user", content="Hello!")
            ],
            model="gpt-4o",
            model_provider=None,
            stream=False
        )
        response = await client.generate(request)
        print(response)
        
        # Example 2: Streaming response
        stream_request = AiRequest(
            messages=[
                Message(role="system", content="You are a helpful assistant."),
                Message(role="user", content="Tell me a story!")
            ],
            stream=True
        )
        async for chunk in await client.generate(stream_request):
            print(chunk)

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

API Reference

Client Initialization

The SDK provides two client classes:

  • MiraSyncClient: Synchronous client using requests
  • MiraClient: Asynchronous client using httpx

Both clients support context managers for proper resource cleanup:

# Synchronous
with MiraSyncClient(
    api_token="your-api-token",
    base_url="https://apis.mira.network/"  # Optional, this is the default
) as client:
    # Your sync code here

# Asynchronous
async with MiraClient(
    api_token="your-api-token",
    base_url="https://apis.mira.network/"  # Optional, this is the default
) as client:
    # Your async code here

Models

  • Message: Represents a chat message

    • role: String ("system", "user", or "assistant")
    • content: String content of the message
  • AiRequest: Configuration for model inference

    • model: Model identifier (default: "mira/llama3.1")
    • messages: List of Message objects
    • stream: Boolean to enable streaming responses (default: False)
    • model_provider: Optional ModelProvider configuration
  • ModelProvider: Custom provider configuration

    • base_url: Provider's base URL
    • api_key: Provider's API key
  • ApiTokenRequest: Request for creating API tokens

    • description: Optional description for the token

Available Methods

Both sync and async clients provide the same methods with identical parameters. The only difference is that async methods must be awaited.

Model Operations

# Sync
models = client.list_models()
response = client.generate(AiRequest(messages=[...], stream=False))
for chunk in client.generate(AiRequest(messages=[...], stream=True)):
    print(chunk)

# Async
models = await client.list_models()
response = await client.generate(AiRequest(messages=[...], stream=False))
async for chunk in await client.generate(AiRequest(messages=[...], stream=True)):
    print(chunk)

API Token Operations

# Sync
token = client.create_api_token(ApiTokenRequest(description="My Token"))
tokens = client.list_api_tokens()
client.delete_api_token("token-to-delete")

# Async
token = await client.create_api_token(ApiTokenRequest(description="My Token"))
tokens = await client.list_api_tokens()
await client.delete_api_token("token-to-delete")

Credit Operations

# Sync
credits = client.get_user_credits()
history = client.get_credits_history()

# Async
credits = await client.get_user_credits()
history = await client.get_credits_history()

License

MIT License

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.5.tar.gz (6.3 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.5-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mira_network-0.1.5.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.21.0 CPython/3.10.15 Darwin/24.2.0

File hashes

Hashes for mira_network-0.1.5.tar.gz
Algorithm Hash digest
SHA256 2ed7851054c52a8ca044d2f2b93aeb7e7fd64e93da4f85d4418bd1413dc52f31
MD5 37784a41e2f28ae8593061ab25a41bd0
BLAKE2b-256 4813e4f9fb86d92012e578f5f8238d44f0778c34d7406418c8d2b1461c81234d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mira_network-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.21.0 CPython/3.10.15 Darwin/24.2.0

File hashes

Hashes for mira_network-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 cf672b022262dc89a31a293380d30a9988d48daca5838ae9629f7829d9847103
MD5 e79475fc2a5de4814a49ef810c55266f
BLAKE2b-256 4e7c9a806f6b53c370ef79e5009aad3fc424a204e4b159f0b714edf1826464ad

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