Skip to main content

Lightweight client for FreeModel's Claude endpoint with retry logic, graceful error handling, and extended thinking support.

Project description

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

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

freemodel_claude-0.2.0.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

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

freemodel_claude-0.2.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file freemodel_claude-0.2.0.tar.gz.

File metadata

  • Download URL: freemodel_claude-0.2.0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for freemodel_claude-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0759e3216771932b4600e4fa1632f5497ff06b57beb936cdd37f81cce159b110
MD5 e5fd494757989a394a23102e6690d6e2
BLAKE2b-256 388a07e2d5767abd8244e521920d252ecb23acb097287b20fd0586897bfce810

See more details on using hashes here.

File details

Details for the file freemodel_claude-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for freemodel_claude-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 48ae1de89ee43cef33be233d61a24b46535c0779de5e608897a0ad2fe23fa005
MD5 bee64e13da45acb35e1569f864568ecd
BLAKE2b-256 a29c4f3f1d5f5c9fa52bd1e6fe0e067761a87630fdf3fd87f79a2288d3921912

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