Skip to main content

Lightweight client for FreeModel's Claude endpoint. Use Claude models (Opus, Sonnet, Haiku) with just a FreeModel API key.

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.1.4.tar.gz (5.2 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.1.4-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: freemodel_claude-0.1.4.tar.gz
  • Upload date:
  • Size: 5.2 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.1.4.tar.gz
Algorithm Hash digest
SHA256 d27bd6020bcca97549d7a44e8e5f2f89cde99e2d7dff290070901bb8b659a469
MD5 7cf150aba10d4d46f714f1eab8cfdc7a
BLAKE2b-256 cd943f16cea79da970e8b778c98ddc06c5c8f0d386c27391c0e33bc3d7bbf27b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for freemodel_claude-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1cf495569f90c89350e4652182b063f4daaa62d7ada5537ac97b8b626e8eb88c
MD5 f31153a0c9e54ae04319e354e7a34a59
BLAKE2b-256 7dc38a5393338120dc0155f4fa297129a1c0f18d539dc7c1697dbbb936ae1a31

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