Skip to main content

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-gateway service
  • A gateway API token

Install

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 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 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:

  • messages is required and must contain at least one message.
  • Each message must only contain role and content.
  • role must be "user" or "assistant".
  • content must be a non-empty string after trimming whitespace.
  • Extra top-level request fields are rejected.
  • stream defaults to False.
  • temperature can be omitted, None, or a number from 0.0 to 2.0.
  • max_tokens can be omitted, None, or an integer greater than 0.
  • system can 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mantis_gw-1.0.0.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

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

mantis_gw-1.0.0-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file mantis_gw-1.0.0.tar.gz.

File metadata

  • Download URL: mantis_gw-1.0.0.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

Hashes for mantis_gw-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6e63fa7ca264250a34555c4f11cf7317cce9a1e944f8f90b307e1d2affed49de
MD5 3b78479f90a361b18eb3a30709837249
BLAKE2b-256 1d8c6af341faced0431da46270286955ad7f1f02fbe82020258cfd4bbddcebc2

See more details on using hashes here.

File details

Details for the file mantis_gw-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mantis_gw-1.0.0-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

Hashes for mantis_gw-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3d74765554c2042ec5b82e776132365450b8f25d9091fdd47603417d0a206f12
MD5 b79951ef53972580a922f4eeaee8dbdd
BLAKE2b-256 bccb5d72c4133c6175b94be7474c4d27da35de7b84a7a6858bbff740169550ee

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