API reference¶
Clients¶
freetheai.FreeTheAI
¶
Bases: _Base
Client for the FreeTheAI API.
from freetheai import FreeTheAI
client = FreeTheAI() # reads FREETHEAI_API_KEY
reply = client.chat.completions.create(
model="fta/zai/glm-5.3",
messages=[{"role": "user", "content": "Hello!"}],
)
print(reply["choices"][0]["message"]["content"])
fallback_models are tried in order when a model is busy, filtered,
over its provider budget, or down. max_concurrency caps replies in
flight; without it the client learns the account's limit by itself.
stream_transport (on by default) fetches non-streamed chats as a
stream and assembles them, which keeps long replies from timing out.
freetheai.AsyncFreeTheAI
¶
Resources¶
| Attribute | Methods |
|---|---|
client.chat.completions |
create(model, messages, stream=False, fallback_models=None, **params), stream_text(model, messages, **params) |
client.models |
list() |
client.videos |
create(model, prompt=None, **params) |
client.images |
generate(model, prompt, **params) |
client.tasks |
list(limit=None), get(task_id), wait(task_id, poll_interval=5, timeout=1800), content(task_id, index=0) |
The async client has the same resources with awaitable methods.
Errors¶
Errors raised by the client, and how each API answer maps onto them.
The API's error bodies are stable, so the client recognises the common cases (daily check-in, daily limit, a busy model, a content filter, ...) and raises a specific class you can catch, with the error id to quote when you ask for support.
FreeTheAIError
¶
Bases: Exception
Base class for every error this package raises.
APIConnectionError
¶
Bases: FreeTheAIError
The request never got an answer (network error or timeout).
StreamInterruptedError
¶
Bases: FreeTheAIError
A streamed reply stopped before the model said it was finished.
partial holds the text that arrived before the cut.
TaskFailedError
¶
APIStatusError
¶
BadRequestError
¶
ContentFilterError
¶
Bases: BadRequestError
400: the model's content filter refused the request or its reply. Rephrasing or another model usually works.
ImagesNotSupportedError
¶
RequestTooLargeError
¶
Bases: APIStatusError
413: the request body is over the size limit (shorten the chat or drop images).
AuthenticationError
¶
IncompleteKeyError
¶
Bases: AuthenticationError
The key is only part of a key (a copied prefix, or cut off). Keys are shown once; create a new one if you lost it.
PermissionDeniedError
¶
CheckinRequiredError
¶
EmailNotVerifiedError
¶
NotFoundError
¶
ModelNotFoundError
¶
RateLimitError
¶
ConcurrencyLimitError
¶
DailyLimitError
¶
ProviderBudgetError
¶
Bases: RateLimitError
429: today's token budget for this model's provider is used up. Models from other providers still work.
InternalServerError
¶
ModelBusyError
¶
Bases: InternalServerError
503: every route for this model is busy; retry later or use another model.