freemodel-claude
Lightweight Python client for FreeModel's Claude endpoint. Use Anthropic Claude models (Opus, Sonnet, Haiku) with just a FreeModel API key.
Install
pip install freemodel-claude
Quick start
from freemodel_claude import ClaudeClient
client = ClaudeClient("your-api-key-here")
# Simple ask
response = client.ask("What is 2+2?")
print(response.text) # "4"
# Pick a model
response = client.ask("Write a haiku", model="claude-opus-4-8")
print(response.text)
# Streaming
for chunk in client.stream("Tell me a story"):
print(chunk, end="", flush=True)
# System prompt
response = client.ask("Debug this", system="You are a senior Python developer.")
# Full metadata
response = client.ask("Explain quantum computing")
print(response.text)
print(response.usage) # token counts, model, stop reason
Models
| Model | Description |
|---|---|
claude-opus-4-8 |
Opus 4.8 — most capable |
claude-opus-4-7 |
Opus 4.7 |
claude-sonnet-4-6 |
Sonnet 4.6 — balanced (default) |
claude-opus-4-6 |
Opus 4.6 |
claude-haiku-4-5-20251001 |
Haiku 4.5 — fastest |
client.models() # tuple of available model names
Invalid model names raise ValueError.
Thinking
Extended thinking is enabled by default (thinking_budget=4095). The upstream API redacts thinking output — response.thinking will always be empty, but response.usage.thinking_tokens reports the count.
Disable thinking to save tokens:
response = client.ask("Hi", thinking_budget=None)
Error handling
All errors raise subclasses of FreeModelError:
| Exception | When |
|---|---|
AuthError |
Invalid API key (401/403) |
RateLimitError |
Rate limited (429) |
APIError |
Other HTTP errors (status + body) |
ConnectionError |
Network failure (timeout, DNS, etc.) |
from freemodel_claude import ClaudeClient, AuthError, RateLimitError
client = ClaudeClient("bad-key")
try:
client.ask("Hi")
except AuthError:
print("Invalid key")
except RateLimitError:
print("Slow down")
Context manager
Reuses the underlying HTTP connection across requests:
with ClaudeClient("your-api-key") as client:
r1 = client.ask("Hello")
r2 = client.ask("Goodbye")
API key
Get one at freemodel.dev. Pass it to the constructor or set FREEMODEL_API_KEY:
import os
client = ClaudeClient(os.environ["FREEMODEL_API_KEY"])
Requirements
- Python >= 3.10
- httpx >= 0.27
Metadata
Release files for freemodel-claude 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| freemodel_claude-0.2.0.tar.gz | 15.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| freemodel_claude-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.9 kB
Release files / freemodel_claude-0.2.0.tar.gz
| Download URL | freemodel_claude-0.2.0.tar.gz |
|---|---|
| Size | 15.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0759e3216771932b4600e4fa1632f5497ff06b57beb936cdd37f81cce159b110
|
|
BLAKE2b-256 checksum How to use checksums |
388a07e2d5767abd8244e521920d252ecb23acb097287b20fd0586897bfce810
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / freemodel_claude-0.2.0-py3-none-any.whl
| Download URL | freemodel_claude-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
48ae1de89ee43cef33be233d61a24b46535c0779de5e608897a0ad2fe23fa005
|
|
BLAKE2b-256 checksum How to use checksums |
a29c4f3f1d5f5c9fa52bd1e6fe0e067761a87630fdf3fd87f79a2288d3921912
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|