Skip to content

Python SDK

The Mantis SDK wraps the /v1/chat/completions endpoint for Python applications.

Terminal window
pip install mantis-gw

The package is imported as mantis_gw.

import asyncio
from mantis_gw import gateway
async def main() -> None:
client = gateway.Gateway(
url="https://gateway.example.com",
token="gw_token-id_token-secret",
)
response = await client.send(
{
"messages": [
{"role": "user", "content": "Write a short project summary."},
],
"stream": False,
"temperature": 0.5,
"max_tokens": 256,
"system": "Answer clearly and concisely.",
},
metadata={"task-type": "summarization"},
)
print(response)
asyncio.run(main())
import asyncio
from mantis_gw import gateway
async def main() -> None:
client = gateway.Gateway(
url="https://gateway.example.com",
token="gw_token-id_token-secret",
)
chunks = await client.send(
{
"messages": [
{"role": "user", "content": "Write a short project summary."},
],
"stream": True,
"temperature": 0.5,
"max_tokens": 256,
},
metadata={"task-type": "summarization"},
)
async for chunk in chunks:
print(chunk, end="")
asyncio.run(main())

Gateway responses with 4xx or 5xx status codes raise httpx.HTTPStatusError.