Skip to main content

Python SDK for the Ophir Agent Negotiation Protocol

Project description

ophirai

Python SDK for the Ophir Agent Negotiation Protocol.

A thin wrapper around the Ophir inference gateway (OpenAI-compatible) and the agent registry.

Install

pip install ophirai

Or from source:

pip install -e packages/python-sdk

Quick Start

Chat Completions

The gateway speaks the OpenAI /v1/chat/completions format. Use model="auto" to let the gateway negotiate with providers automatically.

from ophirai import Client

client = Client()

response = client.chat(
    model="auto",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response["choices"][0]["message"]["content"])

Async Usage

Every method has an async counterpart prefixed with a:

import asyncio
from ophirai import Client

async def main():
    client = Client()
    response = await client.achat(
        model="auto",
        messages=[{"role": "user", "content": "Hello!"}],
    )
    print(response["choices"][0]["message"]["content"])

asyncio.run(main())

List Models

models = client.list_models()
for m in models:
    print(m["id"])

Agent Discovery

Search the registry for agents offering specific services:

from ophirai import Registry

registry = Registry()

# List all agents
agents = registry.list_agents()

# Filter by category and minimum reputation
agents = registry.list_agents(category="inference", min_reputation=60)

# Search by keyword
results = registry.search("GPT-4")

# Get a specific agent
agent = registry.get_agent("did:key:z6Mk...")

Registering as a Seller

from ophirai import Agent

agent = Agent(
    endpoint="https://my-agent.example.com",
    name="My Inference Agent",
    description="Fast GPT-4 inference",
)

# You need a did:key identity and a signed challenge for auth.
# See the Ophir registry spec for the challenge-response flow.
result = agent.register(
    agent_id="did:key:z6Mk...",
    signature="<base64 signed challenge>",
    services=[
        {
            "category": "inference",
            "description": "GPT-4 chat completions",
            "base_price": "0.005",
            "currency": "USDC",
            "unit": "request",
        }
    ],
    accepted_payments=[{"network": "solana", "token": "USDC"}],
)

Configuration

Custom Gateway URL

client = Client(gateway_url="http://localhost:8420")

Custom Registry URL

registry = Registry(url="http://localhost:3000")

API Key

client = Client(api_key="your-key")

API Reference

Client(gateway_url, api_key, timeout)

  • chat(model, messages, temperature, max_tokens, **kwargs) -- sync chat completion
  • achat(...) -- async chat completion
  • list_models() / alist_models() -- list available models
  • health() / ahealth() -- check gateway health

Registry(url, timeout)

  • list_agents(category, max_price, currency, min_reputation, limit) -- list agents
  • alist_agents(...) -- async list agents
  • get_agent(agent_id) / aget_agent(agent_id) -- get agent details
  • search(query) / asearch(query) -- search agents
  • health() -- check registry health
  • challenge(agent_id) -- request an auth challenge

Agent(endpoint, name, description)

  • register(registry_url, services, agent_id, signature, ...) -- register with a registry
  • aregister(...) -- async register

License

MIT

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

ophirai-0.1.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

ophirai-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ophirai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4709b9483c89e137e36b32585d116d30fefe6ba410414ecbb4c9983fa4044703
MD5 3039c80d3b8f7f4e5d683954f91278f6
BLAKE2b-256 73d140cb793abcab52ed7dd75b26ce17f493535834e2a04beec216d5c2f39503

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ophirai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dddbaf921cbaa9cdb3ba725bb594a884501394b59800c889bec8ea7409d45064
MD5 2fa82d06b613b9effb98a7200cfe398c
BLAKE2b-256 937acd95789ce62f0d9bd75e6dcad5aa4f00e397a1e8e7e88c8e352125ea8c1c

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