Skip to main content

kani-ext-vllm

This Kani extension repository adds 3 engines for using vLLM to deploy LLMs on local hardware.

vLLM is an LLM deployment platform optimized for GPU memory efficiency and throughput. This extension adds Kani engines to use vLLM engines in offline mode, manage a vLLM server, or connect to an existing vLLM server depending on the use case.

To install this package, you can install it from PyPI:

$ pip install kani-ext-vllm

Alternatively, you can install it using the git source:

$ pip install git+https://github.com/zhudotexe/kani-ext-vllm.git@main

See https://docs.vllm.ai/en/latest/index.html for more information on vLLM.

Usage

This package provides 3 main methods of serving models with vLLM:

  • Offline mode
  • vLLM-Native API mode
  • OpenAI-Compatible API mode

These are generally equivalent, but offer slightly different options for each mode:

Mode Communication Multiple Parallel Models? Prompt Template/Parsing Best For
Offline Local No kani Low-level control over the model
vLLM API HTTP Yes kani Running multiple different models in parallel
OpenAI API HTTP Yes vLLM Fast iteration and testing multiple models; multimodal models

Offline Mode

from kani import Kani, chat_in_terminal
from kani.ext.vllm import VLLMEngine

engine = VLLMEngine(model_id="meta-llama/Meta-Llama-3-8B-Instruct")
ai = Kani(engine)
chat_in_terminal(ai)

vLLM-Native API Mode

The API mode can be used to connect to an existing running vLLM server or to start a managed vLLM server.

Connecting to a Running Server

from kani import Kani, chat_in_terminal
from kani.ext.vllm import VLLMServerEngine

engine = VLLMServerEngine(
    model_id="meta-llama/Meta-Llama-3-8B-Instruct",
    vllm_host="127.0.0.1",
    vllm_port=8000,
    use_managed_server=False,
)
ai = Kani(engine)
chat_in_terminal(ai)

Managed Server

[!NOTE] The vLLM server will be started on a random free port. It will not be exposed to the wider internet (i.e, it binds to localhost).

from kani import Kani, chat_in_terminal
from kani.ext.vllm import VLLMServerEngine

engine = VLLMServerEngine(model_id="meta-llama/Meta-Llama-3-8B-Instruct")
ai = Kani(engine)
chat_in_terminal(ai)

OpenAI-Compatible API Mode

Connecting to a Running Server

from kani import Kani, chat_in_terminal
from kani.ext.vllm import VLLMOpenAIEngine

engine = VLLMOpenAIEngine(
    model_id="meta-llama/Meta-Llama-3-8B-Instruct",
    vllm_host="127.0.0.1",
    vllm_port=8000,
    use_managed_server=False,
)
ai = Kani(engine)
chat_in_terminal(ai)

Managed Server

[!NOTE] The vLLM server will be started on a random free port. It will not be exposed to the wider internet (i.e, it binds to localhost).

from kani import Kani, chat_in_terminal
from kani.ext.vllm import VLLMOpenAIEngine

engine = VLLMOpenAIEngine(model_id="meta-llama/Meta-Llama-3-8B-Instruct")
ai = Kani(engine)
chat_in_terminal(ai)

Using Multiple GPUs

For multi-GPU support (probably needed), add model_load_kwargs={"tensor_parallel_size": 4}. Replace "4" with the number of GPUs you have available.

[!NOTE] If you are loading in an API mode, use vllm_args={"tensor_parallel_size": 4} instead.

Examples

Offline Mode

from kani.ext.vllm import VLLMEngine
from vllm import SamplingParams

model = VLLMEngine(
    model_id="mistralai/Mistral-Small-Instruct-2409",
    model_load_kwargs={"tensor_parallel_size": 2, "tokenizer_mode": "auto"},
    sampling_params=SamplingParams(temperature=0, max_tokens=2048),
)

vLLM-Native API Mode

from kani.ext.vllm import VLLMServerEngine

model = VLLMServerEngine(
    model_id="mistralai/Mistral-Small-Instruct-2409",
    vllm_args={"tensor_parallel_size": 2, "tokenizer_mode": "auto"},
    # note that these should not be wrapped in SamplingParams!
    temperature=0,
    max_tokens=2048,
)

See https://docs.vllm.ai/en/stable/serving/openai_compatible_server.html#completions-api_1 for a list of valid decoding parameters that can be specified in the engine constructor.

See https://docs.vllm.ai/en/stable/cli/serve/ for a list of valid arguments to vllm_args.

OpenAI-Compatible API Mode

from kani.ext.vllm import VLLMOpenAIEngine

model = VLLMOpenAIEngine(
    model_id="Qwen/Qwen3-Omni-30B-A3B-Instruct",
    vllm_args={"tensor_parallel_size": 2, "allowed_local_media_path": "/"},
    # note that these should not be wrapped in SamplingParams!
    temperature=0,
    max_tokens=2048,
)

See https://docs.vllm.ai/en/stable/serving/openai_compatible_server.html#chat-api_1 for a list of valid decoding parameters that can be specified in the engine constructor.

See https://docs.vllm.ai/en/stable/cli/serve/ for a list of valid arguments to vllm_args.

Metadata

Release files for kani-ext-vllm 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kani-ext-vllm 0.3.1
File Size Uploaded
kani_ext_vllm-0.3.1.tar.gz 17.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kani-ext-vllm 0.3.1
File Interpreter ABI Platform
kani_ext_vllm-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 32.1 kB

Release files / kani_ext_vllm-0.3.1.tar.gz

Download URL kani_ext_vllm-0.3.1.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5d70abda83acb8a85a07fc89435614fe0d29364a41c3f211d430a90e2d0c7b18
BLAKE2b-256 checksum
How to use checksums
9059088e67b22032e927f50929ade057b403e180b19f1e488fac39e9eebeae87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 6, 2026.

Transparency log

Release files / kani_ext_vllm-0.3.1-py3-none-any.whl

Download URL kani_ext_vllm-0.3.1-py3-none-any.whl
Size 14.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0343f84260dcb2ec1b0231629f44df52800c6d16730c35403a4a83b45b531f4e
BLAKE2b-256 checksum
How to use checksums
514e3ac8da8505cf98ba538a398ca53fcccefcb843e837f7aea336b3c45e0aea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 6, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.8

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page