Mantis SDK
Project description
Mantis SDK
Python SDK for sending chat completion requests to the Mantis llm-gateway
/v1/chat/completions endpoint.
Requirements
- Python 3.13+
- A running
llm-gatewayservice - A gateway API token
Install
From PyPI:
pip install mantis_gw
From this repo:
uv sync
Non-streaming
url should be the gateway base URL and should not include /v1/chat/completions.
The SDK appends that endpoint path automatically.
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
When stream is True, send() returns an async iterator of text chunks.
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,
"system": "Answer clearly and concisely.",
},
metadata={"task-type": "summarization"},
)
async for chunk in chunks:
print(chunk, end="")
asyncio.run(main())
Request Payload
The SDK sends the request payload to llm-gateway as-is. Gateway-side validation
still applies to the endpoint:
messagesis required and must contain at least one message.- Each message must only contain
roleandcontent. rolemust be"user"or"assistant".contentmust be a non-empty string after trimming whitespace.- Extra top-level request fields are rejected.
streamdefaults toFalse.temperaturecan be omitted,None, or a number from0.0to2.0.max_tokenscan be omitted,None, or an integer greater than0.systemcan be omitted,None, or a non-empty string after trimming whitespace.
Metadata
Pass routing metadata with the metadata keyword argument. Keys and values must be strings.
The SDK sends it as the gateway's metadata HTTP header.
await client.send(
{
"messages": [{"role": "user", "content": "Generate a Python function."}],
"stream": False,
},
metadata={"task-type": "code_generation"},
)
Errors
Gateway responses with 4xx or 5xx status codes raise httpx.HTTPStatusError.
Integration Tests
The integration tests read gateway credentials from a local .env file in the
repo root:
MANTIS_GATEWAY_URL=https://gateway.example.com
MANTIS_GATEWAY_TOKEN=gw_token-id_token-secret
Run them with:
uv run pytest
The .env file is ignored by Git so real credentials stay local.
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 mantis_gw-1.0.1.tar.gz.
File metadata
- Download URL: mantis_gw-1.0.1.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c742094573f19a6ca0c3cb430d05a820ce3017e4b1d36ad58a395e4fe527460f
|
|
| MD5 |
d9eed9cb27adf81e965d06c26951afb7
|
|
| BLAKE2b-256 |
0a83ef451c2e489e7c3f4882f0781e0fad1aae1f00c442167261d37d2e0757ba
|
File details
Details for the file mantis_gw-1.0.1-py3-none-any.whl.
File metadata
- Download URL: mantis_gw-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a88f937f8be83f732e4e1bc31061809d635690a640ea033fde062b5fbbf7497
|
|
| MD5 |
ebb9e585e719022b3c425e0bd84b0dda
|
|
| BLAKE2b-256 |
94aba09bed886b4c883114129ef1d9936225dbf5a13d5d0309561dfc44b6b1fe
|