Skip to main content

basemode

PyPI Python CI Docs License

Make chat-tuned LLMs continue text instead of answering it.

basemode provides raw text continuation through the terminal, an async Python API, and an OpenAI-compatible completions server. It selects a prompting method for each model and repairs common artifacts at the join between the prompt and the generated text.

The problem

Ask a chat model to continue a passage and it may answer with an introduction, quote the continuation, or offer to revise it:

> The ship rounded the headland and

I'd be happy to help continue this passage! Here's one possibility:

"The ship rounded the headland and the harbour opened before them..."

Would you like me to continue in a different style?

With basemode, the same prefix produces continuation text directly:

$ basemode "The ship rounded the headland and"
The ship rounded the headland and the wind dropped all at once, as though
the cliffs had swallowed it. Sails that had been drum-tight for three days
went slack, and in the sudden quiet the crew could hear water moving along
the hull.

Install

pip install basemode

Requires Python 3.11 or later. Set the relevant provider key in the environment or a .env file, or save it with basemode keys set PROVIDER.

Quickstart

# Continue a prefix
basemode "The ship rounded the headland and"

# Parallel continuations
basemode "The ship rounded the headland and" -n 3

# Inspect selected strategy and pricing metadata
basemode info claude-sonnet-4-6

# Compare prompting methods and save the best result
basemode bench claude-sonnet-4-6 --save

# Show only key-configured models
basemode models --available

Set a default model with basemode default MODEL. Without one, generation uses gpt-4o-mini. See the installation guide for provider-key names and source installation.

Commands

basemode --help
basemode run --help
basemode models --help
basemode info --help
basemode strategies --help
  • basemode run: stream one or more continuations; this is the default command
  • basemode models: list known models and filter by provider or availability
  • basemode info: inspect a model's normalized ID, strategy, quirks, price, and local health
  • basemode bench: compare strategies using live requests and optionally pin the winner
  • basemode verify: collect durable compatibility evidence with bounded live probes
  • basemode serve: expose an OpenAI-compatible /v1/completions endpoint
  • basemode keys, default, and rate: manage local preferences

How strategy selection works

Different models respond to different prompt shapes: native completion, assistant prefill, a system instruction, few-shot examples, or FIM tokens. basemode chooses in this order:

  1. A strategy supplied for the current call.
  2. A local pin saved by basemode bench --save.
  3. The strategy recorded in the verified-model registry.
  4. A model-name heuristic.

basemode info MODEL reports the selected strategy and its source. bench compares strategies on prose, technical writing, poetry, and dialogue, then scores assistant preambles, refusals, echoed prefixes, chat turns, and stray formatting.

basemode bench claude-opus-5 --samples   # compare
basemode bench claude-opus-5 --save      # pin the winner for this model
┏━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃ Strategy ┃ Score ┃ Flags / error        ┃ Mean s ┃
┡━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│ few_shot │ 0.93  │ quoted               │ 2.07   │
│ system   │ 0.75  │ empty                │ 2.24   │
│ prefill  │ 0.00  │ BadRequestError: ... │ 0.30   │
└──────────┴───────┴──────────────────────┴────────┘

See Strategies for the prompt shapes, scoring rules, and override behavior.

Server

basemode serve exposes POST /v1/completions for clients that support the classic OpenAI completions API, including Tapestry Loom.

pip install 'basemode[server]'
basemode serve --port 8080

Set the client endpoint to http://127.0.0.1:8080/v1/completions. Responses are synchronous JSON; streaming and logprobs are not supported. The CLI reference lists accepted fields.

Python API

from basemode import continue_text, branch_text

async for token in continue_text(
    "The ship rounded the headland and",
    model="gpt-4o-mini",
    max_tokens=120,
):
    print(token, end="", flush=True)

async for idx, token in branch_text(
    "The ship rounded the headland and",
    model="gpt-4o-mini",
    n=3,
    max_tokens=80,
):
    print(idx, token, end="", flush=True)

Documentation and development

The documentation covers configuration, strategy behavior, model evidence, and the complete CLI and Python APIs. To build it locally:

make docs-serve

For repository setup and test commands, see the agent quickstart.

Verified models

The registry currently contains 285 model endpoints with a tested prompt strategy. The full model table lists prices, release dates, strategies, and compatibility quirks. It is generated from the same registry used at runtime.

Metadata

Release files for basemode 0.1.40

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

Source distribution (sdist)

Source distribution for basemode 0.1.40
File Size Uploaded
basemode-0.1.40.tar.gz 1.1 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for basemode 0.1.40
File Interpreter ABI Platform
basemode-0.1.40-py3-none-any.whl Python 3 none any Details

Total release size: 2.0 MB

Release files / basemode-0.1.40.tar.gz

Download URL basemode-0.1.40.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
1c822b72e5eb013848c2cac0635056a5ed99ccfe8f3adb8dab67da4df031b319
BLAKE2b-256 checksum
How to use checksums
2c8c1742b872d3c3be6fe778acd751252232492d64deea5a3c4ab4992a1f29a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.9 {"installer":{"name":"uv","version":"0.12.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":true}

Release files / basemode-0.1.40-py3-none-any.whl

Download URL basemode-0.1.40-py3-none-any.whl
Size 859.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79bdaf7d9a1c238fc01f4f2e8fd0332877717f6b82f2967466cef4ba387f29b0
BLAKE2b-256 checksum
How to use checksums
be4c64b018f3963aeb2a313bb9e3a54acee47f5a14f29a9d51ed0c20e9b7c573
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.9 {"installer":{"name":"uv","version":"0.12.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":true}

Release history Release notifications | RSS feed

0.1.48

2 release files

This release

0.1.40 This release

2 release files

0.1.35

2 release files

0.1.34

2 release files

0.1.33

2 release files

0.1.32

2 release files

0.1.31

2 release files

0.1.30

2 release files

0.1.29

2 release files

0.1.28

2 release files

0.1.27

2 release files

0.1.26

2 release files

0.1.25

2 release files

0.1.24

2 release files

0.1.23

2 release files

0.1.22

2 release files

0.1.21

2 release files

0.1.20

2 release files

0.1.19

2 release files

0.1.18

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

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