python-fastllm 0.0.81


pip install python-fastllm

  Latest version

Released: Nov 24, 2026

Project Links

Meta
Author: Kerem Turgutlu
Requires Python: >=3.10

Classifiers

Programming Language
  • Python :: 3
  • Python :: 3 :: Only

fastllm

fastllm provides a common async interface for Anthropic, OpenAI Responses and Chat, Gemini, and OpenAI-compatible providers such as Kimi. Define messages and tools in a shared format and call acomplete. Select the model and, where needed, its provider without rewriting the conversation or tool loop. Supported features vary by provider.

AsyncResponses provides a streaming Responses API interface over the same providers. It translates input items and events and keeps a canonical ResponseState between turns. For transports without provider continuation ids, it replays that state automatically.

Install

Run pip install python-fastllm or clone from github and install locally.

Setup

from aidialog.msg_parts import Msg, Part, Text, Thinking, ToolUse, InputImage, mk_tool_res_msg, Completion
from fastllm.acomplete import acomplete
from fastllm.types import sample_img_url, sample_doms, sonn, luna, flash
import asyncio, json
def user(text): return Msg(role='user', content=[Text(text)])

async def stream(msgs, model, max_think=0, **kw):
    "Print streamed parts and return the final Completion; limit printed thinking deltas with max_think."
    cnt = 0
    async for o in await acomplete(msgs, model, stream=True, **kw):
        if not isinstance(o, Part): continue
        if isinstance(o, Thinking):
            cnt += 1
            if cnt > max_think: continue
        print(o.formatted, end='', flush=True)
    print()
    return o
mtok = 1024

Chat across providers

Use the same acomplete interface with Claude, GPT, Gemini, or Kimi. Set model and any provider-specific routing arguments:

models = [(sonn, {}), (luna, {}), (flash, {}),
    ('accounts/fireworks/models/kimi-k3', dict(vendor_name='fireworks_ai'))]
for name, kw in models:
    r = await acomplete([user("Translate 'hello' into French. Return only the translation.")],
        model=name, max_tokens=mtok, **kw)
    text = ''.join(p.text for p in r.message.content if isinstance(p, Text))
    print(f"{name}: {text.strip()}")
claude-sonnet-5-5: Bonjour
gpt-6-luna: Bonjour
models/gemini-3.8-flash: Bonjour
accounts/fireworks/models/kimi-k3: bonjour

System prompts

Pass system to supply a system prompt. fastllm translates it to the provider’s format: Anthropic system, a leading OpenAI Responses developer message, or Gemini system_instruction.

sys = "You are a pirate chef. Always respond in pirate speak and mention food. Use one short sentence."

print("Claude: ", end='')
r = await stream([user("What should I do today?")], model=sonn, system=sys, max_tokens=mtok)

print("Gemini: ", end='')
r = await stream([user("What should I do today?")], model=flash, system=sys, max_tokens=mtok)
Claude: Arr, matey, hoist yer sails and hunt fer treasure, then feast on a hearty stew o' salted pork and hardtack!
Gemini: Stir the kraken stew and hoist the mainsail, ye scurvy dog!

Tool calling

Define tools in the shared schema. fastllm translates it to the provider’s tool format. This example handles a tool request, adds the result to the history, and continues the conversation:

tools = [{"type": "function", "function": dict(name="get_weather", description="Get current weather for a city",
    parameters=dict(type="object", properties={"city": {"type": "string"}}, required=["city"]))}]

msgs = [user("What's the weather in Paris?")]
r1 = await stream(msgs, model=sonn, tools=tools, max_tokens=mtok)
print("Tool calls:", r1.tool_calls)
- ⏳ `get_weather(city="Paris")` ⏳

Tool calls: [ToolUse(raw={'caller': {'type': 'direct'}}, cache_control=None, id='toolu_01YV9njAjzo17oXmCuaLw6qz', name='get_weather', arguments={'city': 'Paris'}, server=False, text=None)]
msgs += [r1.message, mk_tool_res_msg(r1.tool_calls, ['22°C, sunny with light clouds']),
    user("Should I bring a jacket? Answer in one short sentence.")]
r2 = await stream(msgs, model=sonn, tools=tools, max_tokens=mtok)
At 22°C and sunny, you probably won't need a jacket, though a light layer could help in the evening.

Tool Choice

Control whether the model must use tools, can’t use tools, or decides on its own. The current Claude models reject required and named tool choices. This example uses luna:

r = await acomplete([user('Hello there!')], model=luna, tools=tools, tool_choice='required', max_tokens=mtok)
print("Required:", [tc.name for tc in r.tool_calls])

r = await acomplete([user("What's the weather?")], model=luna, tools=tools, tool_choice='none', max_tokens=mtok)
print("None:", r.tool_calls)
Required: ['get_weather']
None: []

Thinking and extended reasoning

Set reasoning_effort to low, medium, or high for supported models. The adapters translate these values to provider-specific settings. Reasoning output uses Thinking parts; this example prints a short excerpt alongside the answer.

print("Claude: ", end='')
r = await stream([user("What is 127 × 849? Return just the number.")], model=sonn,
    reasoning_effort='low', max_tokens=8192)
for p in r.message.content:
    if isinstance(p, Thinking): print(f"Thinking excerpt: {p.text[:150]}...")

print("Kimi: ", end='')
r = await stream([user('What is 127 × 849? Return just the number.')], model='accounts/fireworks/models/kimi-k3',
    vendor_name='fireworks_ai', reasoning_effort='low', max_tokens=8192)
for p in r.message.content:
    if isinstance(p, Thinking): print(f"Thinking excerpt: {p.text[:150]}...")
Claude: 127 × 849 = 127 × 800 + 127 × 49 = 101600 + 6223 = 107823

107823
Kimi: 107823
Thinking excerpt: The user wants 127 × 849. Let me compute: 127 × 849 = 127 × (850 - 1) = 107950 - 127 = 107823. Check: 849 × 127. 849 × 100 = 84900, 849 × 27 = 22923, ...

Web Search (Server Tools)

OpenAI’s Responses API supports server-side web search. Server tool calls are normalized alongside regular tool calls:

ws_tools = [{"type": "web_search_preview"}]
r = await acomplete([user("What is the latest Python release? Reply with the version number only.")],
    model=luna, tools=ws_tools, max_tokens=512)
print("Server tools used:", [tc.name for tc in r.tool_calls if tc.server])
Server tools used: ['web_search']

Caching with Anthropic

Set a part’s cache_control to request prompt caching. Later requests can reuse eligible cached content. The example prints usage for two calls with the same system prompt:

long_ctx = "You are an expert on the solar system. " * 200
system = Text(long_ctx, cache_control={'type': 'ephemeral'})

r1 = await acomplete([user("What is Jupiter's mass? Answer in one sentence.")],
    model=sonn, system=system, max_tokens=mtok)
print("First call: cache creation tokens", r1.usage.cache_creation_tokens)

r2 = await acomplete([user("What is Saturn's mass? Answer in one sentence.")],
    model=sonn, system=system, max_tokens=mtok)
print("Second call: cache read tokens", r2.usage.cached_tokens)
First call: cache creation tokens 2203
Second call: cache read tokens 2203

Media inputs

Use InputImage with a model that supports images. The example sends the same image message to three providers:

img_msg = Msg(role='user', content=[InputImage(sample_img_url), Text('List three visible objects, using nouns only.')])

for name, kw in [(sonn, {}), (luna, {}), (flash, {})]:
    print(f"{name}: ", end='')
    r = await stream([img_msg], model=name, max_tokens=mtok, **kw)
claude-sonnet-5-5: 1. Mountains
2. Lake
3. Trees
gpt-6-luna: Mountains, trees, lake
models/gemini-3.8-flash: 1. Mountains
2. Lake
3. Deck

The media adapters support the following part types:

Media part Anthropic OpenAI Responses OpenAI Chat Gemini
InputImage Yes Yes Yes Yes
InputAudio No No Yes Yes
InputVideo No No No Yes
InputFile Yes Yes Yes Yes

Media parts accept a URL or base64 data URL as their text. An unsupported combination raises ValueError.

0.0.81 Nov 24, 2026
0.0.80 Nov 23, 2026
0.0.79 Nov 23, 2026
0.0.78 Nov 22, 2026
0.0.77 Nov 22, 2026
0.0.76 Nov 21, 2026
0.0.75 Nov 19, 2026
0.0.74 Nov 19, 2026
0.0.73 Nov 18, 2026
0.0.72 Nov 17, 2026
0.0.71 Nov 16, 2026
0.0.70 Nov 04, 2026
0.0.69 Nov 04, 2026
0.0.68 Nov 03, 2026
0.0.67 Nov 03, 2026
0.0.66 Oct 27, 2026
0.0.65 Oct 08, 2026
0.0.64 Sep 29, 2026
0.0.63 Sep 22, 2026
0.0.62 Sep 16, 2026
0.0.61 Sep 11, 2026
0.0.60 Sep 09, 2026
0.0.59 Sep 08, 2026
0.0.58 Sep 06, 2026
0.0.57 Sep 04, 2026
0.0.56 Sep 04, 2026
0.0.55 Sep 04, 2026
0.0.54 Sep 04, 2026
0.0.53 Sep 03, 2026
0.0.52 Sep 03, 2026
0.0.51 Sep 02, 2026
0.0.50 Sep 02, 2026
0.0.49 Sep 02, 2026
0.0.48 Sep 02, 2026
0.0.47 Sep 02, 2026
0.0.46 Sep 01, 2026
0.0.45 Sep 01, 2026
0.0.44 Sep 01, 2026
0.0.43 Aug 27, 2026
0.0.42 Aug 24, 2026
0.0.41 Aug 13, 2026
0.0.40 Aug 09, 2026
0.0.39 Aug 06, 2026
0.0.38 Aug 05, 2026
0.0.37 Aug 04, 2026
0.0.36 Aug 01, 2026
0.0.35 Jul 31, 2026
0.0.34 Jul 31, 2026
0.0.33 Jul 29, 2026
0.0.32 Jul 27, 2026
0.0.31 Jul 24, 2026
0.0.30 Jul 20, 2026
0.0.29 Jul 15, 2026
0.0.28 Jul 14, 2026
0.0.27 Jul 02, 2026
0.0.26 Jul 01, 2026
0.0.25 Jul 01, 2026
0.0.24 Jun 29, 2026
0.0.23 Jun 24, 2026
0.0.22 Jun 22, 2026
0.0.21 Jun 18, 2026
0.0.20 Jun 16, 2026
0.0.19 Jun 12, 2026
0.0.18 Jun 11, 2026
0.0.17 Jun 11, 2026
0.0.16 Jun 09, 2026
0.0.15 Jun 09, 2026
0.0.14 Jun 08, 2026
0.0.12 Jun 03, 2026
0.0.11 Jun 01, 2026
0.0.10 May 27, 2026
0.0.9 May 20, 2026
0.0.8 May 19, 2026
0.0.7 May 14, 2026
0.0.6 May 12, 2026
0.0.5 May 12, 2026
0.0.4 May 11, 2026
0.0.3 May 07, 2026
0.0.2 May 06, 2026
0.0.1 May 06, 2026

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
fastcore (>=2.2.14)
aidialog (>=0.0.38)
fasttransport (>=0.0.2)
pillow