Python SDK
The Mantis SDK wraps the /v1/chat/completions endpoint for Python applications.
Install
Section titled “Install”pip install mantis-gwThe package is imported as mantis_gw.
Non-streaming
Section titled “Non-streaming”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())Streaming
Section titled “Streaming”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())Errors
Section titled “Errors”Gateway responses with 4xx or 5xx status codes raise httpx.HTTPStatusError.