Python SDK for the Optimus API — MSC construction, routing, and answers
Project description
agent-optimus
Python SDK for the Optimus backend API. Install with pip and call MSC construction, model routing, and full answer generation from Python.
Installation
pip install agent-optimus
Quick start
You can use Optimus with the exact same call pattern as OpenRouter/OpenAI. Only the import and API key differ.
Option 1 — built-in client (recommended, no extra install)
from agent_optimus import OpenAI
client = OpenAI(api_key="your-optimus-api-token")
response = client.chat.completions.create(
model="qwen/qwen3-32b",
messages=[
{"role": "user", "content": "Hello"}
],
)
print(response.choices[0].message.content)
base_url defaults to production. Override only for local development:
client = OpenAI(
api_key="your-optimus-api-token",
base_url="http://127.0.0.1:8000",
)
Option 2 — official openai package
If you need the real OpenAI SDK types/objects:
pip install agent-optimus[openai]
from openai import OpenAI
from agent_optimus import create_openai_client
client = create_openai_client(api_key="your-optimus-api-token")
response = client.chat.completions.create(
model="qwen/qwen3-32b",
messages=[
{"role": "user", "content": "Hello"}
],
)
print(response.choices[0].message.content)
Note:
from openai import OpenAIalone cannot talk to Optimus directly, because Optimus uses/finishinstead of OpenAI's/v1/chat/completions.create_openai_client()wires that up for you.
Optimus-specific fields (routing_score, cost_usd, metrics) are available on response.optimus (built-in client) or inside the raw response payload (official client).
Native SDK usage
from agent_optimus import AgentOptimus
client = AgentOptimus(api_token="your-api-key")
# 1. Build an MSC from long context
msc = client.construct_msc(
context="Italy dominates European silk production...",
user_query="Who leads silk production in Europe?",
)
print(msc["msc_string"], msc["compression_ratio"])
# 2. Route only (no full MSC + answer pipeline)
routed = client.route(
context="The Eiffel Tower is in Paris.",
query="Where is the Eiffel Tower?",
)
print(routed["content"], routed["model_provider_detail"])
# 3. Full pipeline answer (MSC + route + generate)
answer = client.answer(
context="The Eiffel Tower is in Paris.",
query="Where is the Eiffel Tower?",
)
print(answer["content"], answer["metrics"])
You can also pass api_token per call instead of on the client:
client = AgentOptimus(base_url="http://127.0.0.1:8000")
result = client.route(api_token="your-api-key", context="...", query="...")
Configuration
| Setting | Default | Override |
|---|---|---|
| Base URL | https://api-optimus-backend-service.up.railway.app |
AGENT_OPTIMUS_BASE_URL env var or base_url= |
| OpenAI client | OpenAI(api_key=...) |
api_key= |
| Native client | AgentOptimus(api_token=...) |
api_token= on client or each method |
| Auth header | x-api-token |
fixed |
API mapping
| SDK method | HTTP | Path |
|---|---|---|
OpenAI.chat.completions.create() |
POST | /finish |
construct_msc() |
POST | /generate-msc |
route() |
POST | /route |
answer() |
POST | /finish |
Extra keyword arguments on each method are forwarded in the JSON request body.
PyPI auto-publish (GitHub Actions)
Merges to main that touch package files trigger .github/workflows/publish-pypi.yml, which builds and uploads to PyPI.
One-time setup
- Create a PyPI API token at pypi.org/manage/account/token/ (scope: entire account for the first release).
- In your GitHub repo go to Settings → Environments → New environment and create
pypi. - (Optional) Under
pypi, enable Required reviewers and add yourself so publishes need approval. - In the
pypienvironment, add secretPYPI_API_TOKENwith your fullpypi-...token.
Versioning
Bump version in pyproject.toml before merging a release to main. The workflow uses --skip-existing, so pushes without a version bump are no-ops instead of failures.
Development
python3 -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
python3 -m build
Publish to PyPI
python3 -m pip install --upgrade twine
python3 -m twine upload dist/*
When prompted for credentials:
- Username:
__token__ - Password: your PyPI API token (including the
pypi-prefix)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agent_optimus-0.1.0.tar.gz.
File metadata
- Download URL: agent_optimus-0.1.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f218c142f6d359e38f8699d7f3a4fbe560cb1147dce60d18b22fc1ee48acc4b5
|
|
| MD5 |
3eabd859f86548d33a2fa627e4e8f02f
|
|
| BLAKE2b-256 |
13f1d34b5e9b69b37953218e6efc86313ce0a446b2bcd6d7ff5e558ec8d8d812
|
File details
Details for the file agent_optimus-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agent_optimus-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c85dcd647af900b851cda995449865154bee5019f48739893c765ea7da248a17
|
|
| MD5 |
b2c2a7c8c599786ed9a6ec18202bd576
|
|
| BLAKE2b-256 |
29a443387a16ddd0f51a3f1f51936d1d804410aeee39937bbb78b6bae5a4969b
|