freetheai 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. freetheai-0.1.0/.github/banner.jpg +0 -0
  2. freetheai-0.1.0/.github/workflows/docs.yml +37 -0
  3. freetheai-0.1.0/.github/workflows/release.yml +40 -0
  4. freetheai-0.1.0/.github/workflows/test.yml +24 -0
  5. freetheai-0.1.0/.gitignore +10 -0
  6. freetheai-0.1.0/CHANGELOG.md +8 -0
  7. freetheai-0.1.0/LICENSE +21 -0
  8. freetheai-0.1.0/PKG-INFO +123 -0
  9. freetheai-0.1.0/README.md +97 -0
  10. freetheai-0.1.0/docs/assets/banner.jpg +0 -0
  11. freetheai-0.1.0/docs/assets/favicon.png +0 -0
  12. freetheai-0.1.0/docs/assets/logo.png +0 -0
  13. freetheai-0.1.0/docs/changelog.md +5 -0
  14. freetheai-0.1.0/docs/configuration.md +46 -0
  15. freetheai-0.1.0/docs/errors.md +45 -0
  16. freetheai-0.1.0/docs/getting-started.md +75 -0
  17. freetheai-0.1.0/docs/guides/async.md +40 -0
  18. freetheai-0.1.0/docs/guides/chat.md +80 -0
  19. freetheai-0.1.0/docs/guides/media.md +39 -0
  20. freetheai-0.1.0/docs/guides/tools.md +42 -0
  21. freetheai-0.1.0/docs/guides/web-search.md +41 -0
  22. freetheai-0.1.0/docs/index.md +48 -0
  23. freetheai-0.1.0/docs/reference.md +35 -0
  24. freetheai-0.1.0/docs/reliability.md +57 -0
  25. freetheai-0.1.0/mkdocs.yml +97 -0
  26. freetheai-0.1.0/overrides/main.html +18 -0
  27. freetheai-0.1.0/pyproject.toml +56 -0
  28. freetheai-0.1.0/src/freetheai/__init__.py +61 -0
  29. freetheai-0.1.0/src/freetheai/_client.py +678 -0
  30. freetheai-0.1.0/src/freetheai/_errors.py +236 -0
  31. freetheai-0.1.0/src/freetheai/_resilience.py +281 -0
  32. freetheai-0.1.0/src/freetheai/_streaming.py +70 -0
  33. freetheai-0.1.0/src/freetheai/_version.py +1 -0
  34. freetheai-0.1.0/src/freetheai/py.typed +0 -0
  35. freetheai-0.1.0/tests/test_client.py +409 -0
Binary file
@@ -0,0 +1,37 @@
1
+ name: Docs
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ paths: ["docs/**", "mkdocs.yml", "overrides/**", "src/**", "CHANGELOG.md", ".github/workflows/docs.yml"]
7
+ workflow_dispatch:
8
+
9
+ permissions:
10
+ contents: read
11
+ pages: write
12
+ id-token: write
13
+
14
+ concurrency:
15
+ group: pages
16
+ cancel-in-progress: true
17
+
18
+ jobs:
19
+ build:
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+ - uses: astral-sh/setup-uv@v6
24
+ - run: uv run --no-project --with "mkdocs<2" --with mkdocs-material --with "mkdocstrings[python]" mkdocs build --strict
25
+ - uses: actions/upload-pages-artifact@v3
26
+ with:
27
+ path: site
28
+
29
+ deploy:
30
+ needs: build
31
+ runs-on: ubuntu-latest
32
+ environment:
33
+ name: github-pages
34
+ url: ${{ steps.deployment.outputs.page_url }}
35
+ steps:
36
+ - id: deployment
37
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,40 @@
1
+ name: Release
2
+
3
+ # Publishes to PyPI with trusted publishing (no stored token) when a GitHub
4
+ # release is published. The tag must match the package version (v0.1.0).
5
+ on:
6
+ release:
7
+ types: [published]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ build:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: astral-sh/setup-uv@v6
18
+ - name: Check the tag matches the version
19
+ run: |
20
+ version=$(uv run --no-project python -c "import re;print(re.search(r'\"(.+)\"', open('src/freetheai/_version.py').read()).group(1))")
21
+ test "v$version" = "${GITHUB_REF_NAME}"
22
+ - run: uv run --group dev pytest -q
23
+ - run: uv build
24
+ - uses: actions/upload-artifact@v4
25
+ with:
26
+ name: dist
27
+ path: dist/
28
+
29
+ publish:
30
+ needs: build
31
+ runs-on: ubuntu-latest
32
+ environment: pypi
33
+ permissions:
34
+ id-token: write
35
+ steps:
36
+ - uses: actions/download-artifact@v4
37
+ with:
38
+ name: dist
39
+ path: dist/
40
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,24 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ python: ["3.9", "3.10", "3.11", "3.12", "3.13"]
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - uses: astral-sh/setup-uv@v6
20
+ with:
21
+ python-version: ${{ matrix.python }}
22
+ - run: uv run --group dev ruff check src tests
23
+ - run: uv run --group dev ruff format --check src tests
24
+ - run: uv run --group dev pytest -q
@@ -0,0 +1,10 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .venv/
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ uv.lock
10
+ site/
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2026-10-10)
4
+
5
+ First release.
6
+
7
+ - Chat completions (plain and streamed), models, web search and answers, image and video tasks, sync and async clients.
8
+ - Built-in handling for the FreeTheAI API: fallback models, a learned concurrency limit, retries on busy models with `Retry-After`, non-streamed chats fetched as a stream, cut-off stream detection, model ID suggestions and prefix fixes, key cleanup, and a specific error class for each common API answer.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 FreeTheAI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.5
2
+ Name: freetheai
3
+ Version: 0.1.0
4
+ Summary: Official Python SDK for FreeTheAI: a free OpenAI-compatible AI API with chat, streaming, web search, and image and video tasks.
5
+ Project-URL: Homepage, https://freetheai.org
6
+ Project-URL: Documentation, https://freetheai.org/docs
7
+ Project-URL: Repository, https://github.com/Free-The-Ai/freetheai-python
8
+ Project-URL: Issues, https://github.com/Free-The-Ai/freetheai-python/issues
9
+ Project-URL: Changelog, https://github.com/Free-The-Ai/freetheai-python/releases
10
+ Project-URL: Discord, https://discord.gg/secrets
11
+ Author-email: FreeTheAI <vibheksoni@engineer.com>
12
+ License-Expression: MIT
13
+ License-File: LICENSE
14
+ Keywords: ai sdk,chat completions,free ai api,free llm api,freetheai,llm,openai compatible,streaming,tool calls,web search
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.9
24
+ Requires-Dist: httpx<1,>=0.25
25
+ Description-Content-Type: text/markdown
26
+
27
+ <p align="center">
28
+ <a href="https://free-the-ai.github.io/freetheai-python/"><img src="https://raw.githubusercontent.com/Free-The-Ai/freetheai-python/main/.github/banner.jpg" alt="FreeTheAI Python SDK" width="100%"></a>
29
+ </p>
30
+
31
+ <p align="center">
32
+ <a href="https://pypi.org/project/freetheai/"><img src="https://img.shields.io/pypi/v/freetheai?color=111111" alt="PyPI"></a>
33
+ <a href="https://pypi.org/project/freetheai/"><img src="https://img.shields.io/pypi/pyversions/freetheai?color=111111" alt="Python versions"></a>
34
+ <a href="https://github.com/Free-The-Ai/freetheai-python/actions/workflows/test.yml"><img src="https://github.com/Free-The-Ai/freetheai-python/actions/workflows/test.yml/badge.svg" alt="Tests"></a>
35
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-111111" alt="MIT license"></a>
36
+ <a href="https://discord.gg/secrets"><img src="https://img.shields.io/badge/Discord-join-5865F2?logo=discord&logoColor=white" alt="Discord"></a>
37
+ </p>
38
+
39
+ <p align="center">
40
+ <b><a href="https://free-the-ai.github.io/freetheai-python/">Documentation</a></b> ·
41
+ <a href="https://free-the-ai.github.io/freetheai-python/getting-started/">Getting started</a> ·
42
+ <a href="https://freetheai.org/models">Models</a> ·
43
+ <a href="https://freetheai.org">freetheai.org</a>
44
+ </p>
45
+
46
+ # FreeTheAI Python SDK
47
+
48
+ The official Python client for [FreeTheAI](https://freetheai.org), a free OpenAI-compatible AI API. One key gives you dozens of chat models, streaming, tool calls, web search with sourced answers, and image and video tasks.
49
+
50
+ ```bash
51
+ pip install freetheai
52
+ ```
53
+
54
+ ## Quickstart
55
+
56
+ Create a key at [freetheai.org](https://freetheai.org/dashboard/api-keys), do the [daily check-in](https://freetheai.org/checkin) for free models, and set `FREETHEAI_API_KEY`.
57
+
58
+ ```python
59
+ from freetheai import FreeTheAI
60
+
61
+ client = FreeTheAI()
62
+
63
+ reply = client.chat.completions.create(
64
+ model="fta/zai/glm-5.3",
65
+ messages=[{"role": "user", "content": "Write a haiku about open models."}],
66
+ )
67
+ print(reply["choices"][0]["message"]["content"])
68
+ ```
69
+
70
+ Stream it:
71
+
72
+ ```python
73
+ for text in client.chat.completions.stream_text(model="fta/kimi/k3", messages=messages):
74
+ print(text, end="", flush=True)
75
+ ```
76
+
77
+ Search the web:
78
+
79
+ ```python
80
+ answer = client.answer("What changed in Python 3.14?")
81
+ print(answer["answer"], answer["sources"])
82
+ ```
83
+
84
+ ## Built for the FreeTheAI API
85
+
86
+ Generic OpenAI clients treat every error the same. This one knows how the FreeTheAI API answers:
87
+
88
+ - **Busy models** wait for the server's `Retry-After`, or move straight to your `fallback_models`.
89
+ - **Concurrency limits** are learned on the first refusal; extra calls queue instead of failing.
90
+ - **Long replies** are fetched as a stream and assembled, so they don't hit idle timeouts.
91
+ - **Cut-off streams** raise `StreamInterruptedError` with the partial text, never a silently short answer.
92
+ - **The daily check-in and daily limit** raise `CheckinRequiredError` and `DailyLimitError` at once, with the link or reset time.
93
+ - **Mistyped model IDs** come back with suggestions; a missing `fta/` prefix is fixed for you.
94
+
95
+ ```python
96
+ client = FreeTheAI(fallback_models=["fta/zai/glm-5.3-flash", "fta/mmx/minimax-m3"])
97
+ ```
98
+
99
+ Read [Reliability](https://free-the-ai.github.io/freetheai-python/reliability/) for the full list.
100
+
101
+ ## Documentation
102
+
103
+ | Guide | |
104
+ | --- | --- |
105
+ | [Getting started](https://free-the-ai.github.io/freetheai-python/getting-started/) | Key, check-in, first request |
106
+ | [Chat and streaming](https://free-the-ai.github.io/freetheai-python/guides/chat/) | Parameters, streaming, reasoning, images |
107
+ | [Tool calls](https://free-the-ai.github.io/freetheai-python/guides/tools/) | Function calling step by step |
108
+ | [Web search](https://free-the-ai.github.io/freetheai-python/guides/web-search/) | Results and sourced answers |
109
+ | [Images and video](https://free-the-ai.github.io/freetheai-python/guides/media/) | Media tasks |
110
+ | [Async](https://free-the-ai.github.io/freetheai-python/guides/async/) | `AsyncFreeTheAI` |
111
+ | [Errors](https://free-the-ai.github.io/freetheai-python/errors/) | Every error class and what to do |
112
+ | [Configuration](https://free-the-ai.github.io/freetheai-python/configuration/) | All client options |
113
+
114
+ ## More from FreeTheAI
115
+
116
+ - [JavaScript / TypeScript SDK](https://github.com/Free-The-Ai/freetheai-js) and [Go SDK](https://github.com/Free-The-Ai/freetheai-go)
117
+ - [Cookbook](https://github.com/Free-The-Ai/freetheai-cookbook): runnable examples
118
+ - [Setup guides](https://freetheai.org/setup) for SillyTavern, JanitorAI, Claude Code, Cline, and more
119
+ - [API status](https://freetheai.org/status) and [Discord](https://discord.gg/secrets)
120
+
121
+ ## License
122
+
123
+ MIT
@@ -0,0 +1,97 @@
1
+ <p align="center">
2
+ <a href="https://free-the-ai.github.io/freetheai-python/"><img src="https://raw.githubusercontent.com/Free-The-Ai/freetheai-python/main/.github/banner.jpg" alt="FreeTheAI Python SDK" width="100%"></a>
3
+ </p>
4
+
5
+ <p align="center">
6
+ <a href="https://pypi.org/project/freetheai/"><img src="https://img.shields.io/pypi/v/freetheai?color=111111" alt="PyPI"></a>
7
+ <a href="https://pypi.org/project/freetheai/"><img src="https://img.shields.io/pypi/pyversions/freetheai?color=111111" alt="Python versions"></a>
8
+ <a href="https://github.com/Free-The-Ai/freetheai-python/actions/workflows/test.yml"><img src="https://github.com/Free-The-Ai/freetheai-python/actions/workflows/test.yml/badge.svg" alt="Tests"></a>
9
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-111111" alt="MIT license"></a>
10
+ <a href="https://discord.gg/secrets"><img src="https://img.shields.io/badge/Discord-join-5865F2?logo=discord&logoColor=white" alt="Discord"></a>
11
+ </p>
12
+
13
+ <p align="center">
14
+ <b><a href="https://free-the-ai.github.io/freetheai-python/">Documentation</a></b> ·
15
+ <a href="https://free-the-ai.github.io/freetheai-python/getting-started/">Getting started</a> ·
16
+ <a href="https://freetheai.org/models">Models</a> ·
17
+ <a href="https://freetheai.org">freetheai.org</a>
18
+ </p>
19
+
20
+ # FreeTheAI Python SDK
21
+
22
+ The official Python client for [FreeTheAI](https://freetheai.org), a free OpenAI-compatible AI API. One key gives you dozens of chat models, streaming, tool calls, web search with sourced answers, and image and video tasks.
23
+
24
+ ```bash
25
+ pip install freetheai
26
+ ```
27
+
28
+ ## Quickstart
29
+
30
+ Create a key at [freetheai.org](https://freetheai.org/dashboard/api-keys), do the [daily check-in](https://freetheai.org/checkin) for free models, and set `FREETHEAI_API_KEY`.
31
+
32
+ ```python
33
+ from freetheai import FreeTheAI
34
+
35
+ client = FreeTheAI()
36
+
37
+ reply = client.chat.completions.create(
38
+ model="fta/zai/glm-5.3",
39
+ messages=[{"role": "user", "content": "Write a haiku about open models."}],
40
+ )
41
+ print(reply["choices"][0]["message"]["content"])
42
+ ```
43
+
44
+ Stream it:
45
+
46
+ ```python
47
+ for text in client.chat.completions.stream_text(model="fta/kimi/k3", messages=messages):
48
+ print(text, end="", flush=True)
49
+ ```
50
+
51
+ Search the web:
52
+
53
+ ```python
54
+ answer = client.answer("What changed in Python 3.14?")
55
+ print(answer["answer"], answer["sources"])
56
+ ```
57
+
58
+ ## Built for the FreeTheAI API
59
+
60
+ Generic OpenAI clients treat every error the same. This one knows how the FreeTheAI API answers:
61
+
62
+ - **Busy models** wait for the server's `Retry-After`, or move straight to your `fallback_models`.
63
+ - **Concurrency limits** are learned on the first refusal; extra calls queue instead of failing.
64
+ - **Long replies** are fetched as a stream and assembled, so they don't hit idle timeouts.
65
+ - **Cut-off streams** raise `StreamInterruptedError` with the partial text, never a silently short answer.
66
+ - **The daily check-in and daily limit** raise `CheckinRequiredError` and `DailyLimitError` at once, with the link or reset time.
67
+ - **Mistyped model IDs** come back with suggestions; a missing `fta/` prefix is fixed for you.
68
+
69
+ ```python
70
+ client = FreeTheAI(fallback_models=["fta/zai/glm-5.3-flash", "fta/mmx/minimax-m3"])
71
+ ```
72
+
73
+ Read [Reliability](https://free-the-ai.github.io/freetheai-python/reliability/) for the full list.
74
+
75
+ ## Documentation
76
+
77
+ | Guide | |
78
+ | --- | --- |
79
+ | [Getting started](https://free-the-ai.github.io/freetheai-python/getting-started/) | Key, check-in, first request |
80
+ | [Chat and streaming](https://free-the-ai.github.io/freetheai-python/guides/chat/) | Parameters, streaming, reasoning, images |
81
+ | [Tool calls](https://free-the-ai.github.io/freetheai-python/guides/tools/) | Function calling step by step |
82
+ | [Web search](https://free-the-ai.github.io/freetheai-python/guides/web-search/) | Results and sourced answers |
83
+ | [Images and video](https://free-the-ai.github.io/freetheai-python/guides/media/) | Media tasks |
84
+ | [Async](https://free-the-ai.github.io/freetheai-python/guides/async/) | `AsyncFreeTheAI` |
85
+ | [Errors](https://free-the-ai.github.io/freetheai-python/errors/) | Every error class and what to do |
86
+ | [Configuration](https://free-the-ai.github.io/freetheai-python/configuration/) | All client options |
87
+
88
+ ## More from FreeTheAI
89
+
90
+ - [JavaScript / TypeScript SDK](https://github.com/Free-The-Ai/freetheai-js) and [Go SDK](https://github.com/Free-The-Ai/freetheai-go)
91
+ - [Cookbook](https://github.com/Free-The-Ai/freetheai-cookbook): runnable examples
92
+ - [Setup guides](https://freetheai.org/setup) for SillyTavern, JanitorAI, Claude Code, Cline, and more
93
+ - [API status](https://freetheai.org/status) and [Discord](https://discord.gg/secrets)
94
+
95
+ ## License
96
+
97
+ MIT
Binary file
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: Release notes for the FreeTheAI Python SDK.
3
+ ---
4
+
5
+ --8<-- "CHANGELOG.md"
@@ -0,0 +1,46 @@
1
+ ---
2
+ description: Configuration options for the FreeTheAI Python SDK client.
3
+ ---
4
+
5
+ # Configuration
6
+
7
+ ```python
8
+ import httpx
9
+ from freetheai import FreeTheAI
10
+
11
+ client = FreeTheAI(
12
+ api_key=None, # default: FREETHEAI_API_KEY
13
+ base_url=None, # default: FREETHEAI_BASE_URL or https://api.freetheai.org/v1
14
+ max_retries=3, # retries per model for retryable errors
15
+ fallback_models=None, # models tried in order after the first one fails
16
+ max_concurrency=None, # fixed cap on replies in flight; learned when left out
17
+ stream_transport=True, # fetch non-streamed chats as a stream and assemble them
18
+ timeout=httpx.Timeout(600, connect=15),
19
+ default_headers=None, # extra headers on every request
20
+ http_client=None, # your own httpx.Client (proxies, transports, ...)
21
+ )
22
+ ```
23
+
24
+ | Environment variable | Used for |
25
+ | --- | --- |
26
+ | `FREETHEAI_API_KEY` | The API key when `api_key` isn't passed |
27
+ | `FREETHEAI_BASE_URL` | The API address when `base_url` isn't passed |
28
+
29
+ ## Your own HTTP client
30
+
31
+ Pass an `httpx.Client` for proxies, custom TLS, or event hooks:
32
+
33
+ ```python
34
+ client = FreeTheAI(http_client=httpx.Client(proxy="http://localhost:8080", timeout=120))
35
+ ```
36
+
37
+ The client sets the `Authorization` and `User-Agent` headers itself.
38
+
39
+ ## Closing
40
+
41
+ Use the client as a context manager, or call `close()`:
42
+
43
+ ```python
44
+ with FreeTheAI() as client:
45
+ ...
46
+ ```
@@ -0,0 +1,45 @@
1
+ ---
2
+ description: Every error class in the FreeTheAI Python SDK, when it is raised, and what to do about it.
3
+ ---
4
+
5
+ # Errors
6
+
7
+ All errors inherit from `FreeTheAIError`. API errors (`APIStatusError` and its subclasses) carry `status_code`, `message`, `code`, `error_id`, and `body`.
8
+
9
+ ```python
10
+ from freetheai import CheckinRequiredError, DailyLimitError, FreeTheAIError
11
+
12
+ try:
13
+ reply = client.chat.completions.create(model="fta/zai/glm-5.3", messages=messages)
14
+ except CheckinRequiredError as error:
15
+ print("Do the daily check-in:", error.checkin_url)
16
+ except DailyLimitError as error:
17
+ print("Free requests are used up until", error.resets_at)
18
+ except FreeTheAIError as error:
19
+ print("Failed:", error)
20
+ ```
21
+
22
+ | Error | Status | When | What to do |
23
+ | --- | --- | --- | --- |
24
+ | `IncompleteKeyError` | 401 | The key is only part of a key | Copy the whole key, or create a new one |
25
+ | `AuthenticationError` | 401 | The key is wrong or revoked | Check the key on the [API keys page](https://freetheai.org/dashboard/api-keys) |
26
+ | `CheckinRequiredError` | 403 | Free models need today's check-in | Visit `error.checkin_url` |
27
+ | `EmailNotVerifiedError` | 403 | The account's email isn't confirmed | Confirm it on the website |
28
+ | `PermissionDeniedError` | 403 | The key's scope or IP list doesn't allow this | Check the key's settings |
29
+ | `ModelNotFoundError` | 404 | No model has this ID | See `error.suggestions` |
30
+ | `NotFoundError` | 404 | Unknown task or route | |
31
+ | `BadRequestError` | 400 | The request is invalid | Read `error.message` |
32
+ | `ContentFilterError` | 400 | The model's content filter refused | Rephrase or use another model |
33
+ | `ImagesNotSupportedError` | 400 | The model reads text only | Remove images or pick another model |
34
+ | `RequestTooLargeError` | 413 | Over 8 MiB | Shorten the chat or drop images |
35
+ | `ConcurrencyLimitError` | 429 | Too many replies running (only after the client's own queueing gives up) | Wait for running replies |
36
+ | `DailyLimitError` | 429 | Today's free requests are used | Wait until `error.resets_at` |
37
+ | `ProviderBudgetError` | 429 | This provider's daily token budget is used | Use a model from another provider |
38
+ | `RateLimitError` | 429 | Too many requests | Slow down |
39
+ | `ModelBusyError` | 503 | Every route for the model is busy | Retry later or add fallback models |
40
+ | `InternalServerError` | 5xx | The service is temporarily unavailable | Retry later |
41
+ | `StreamInterruptedError` | | A stream stopped early | `error.partial` has the text so far |
42
+ | `TaskFailedError` | | An image or video task ended without output | Read `error.message` |
43
+ | `APIConnectionError` | | No answer (network or timeout) | Check your connection |
44
+
45
+ Include `error.error_id` when you ask for help.
@@ -0,0 +1,75 @@
1
+ ---
2
+ description: Install the FreeTheAI Python SDK, create a free API key, do the daily check-in, and send your first request.
3
+ ---
4
+
5
+ # Getting started
6
+
7
+ ## 1. Install
8
+
9
+ ```bash
10
+ pip install freetheai
11
+ ```
12
+
13
+ Python 3.9 or newer. The only dependency is `httpx`.
14
+
15
+ ## 2. Get a key
16
+
17
+ 1. Sign up at [freetheai.org](https://freetheai.org).
18
+ 2. Open [API keys](https://freetheai.org/dashboard/api-keys) and create a key. It starts with `ftai_` and is shown once, so copy all of it.
19
+ 3. Free models need the [daily check-in](https://freetheai.org/checkin), one quick captcha a day.
20
+
21
+ The free tier is 50 requests a day, reset at 00:00 UTC. The [plan page](https://freetheai.org/dashboard/plan) shows how to raise it.
22
+
23
+ Put the key in the environment:
24
+
25
+ === "macOS / Linux"
26
+
27
+ ```bash
28
+ export FREETHEAI_API_KEY="ftai_..."
29
+ ```
30
+
31
+ === "Windows (PowerShell)"
32
+
33
+ ```powershell
34
+ $env:FREETHEAI_API_KEY = "ftai_..."
35
+ ```
36
+
37
+ ## 3. Pick a model
38
+
39
+ Model IDs look like `fta/<provider>/<model>`. Browse them on [freetheai.org/models](https://freetheai.org/models) or list them in code:
40
+
41
+ ```python
42
+ from freetheai import FreeTheAI
43
+
44
+ client = FreeTheAI()
45
+ for model in client.models.list():
46
+ print(model["id"])
47
+ ```
48
+
49
+ ## 4. Send a request
50
+
51
+ ```python
52
+ reply = client.chat.completions.create(
53
+ model="fta/zai/glm-5.3",
54
+ messages=[
55
+ {"role": "system", "content": "You are a concise assistant."},
56
+ {"role": "user", "content": "What is an API gateway?"},
57
+ ],
58
+ )
59
+ print(reply["choices"][0]["message"]["content"])
60
+ print(reply["usage"])
61
+ ```
62
+
63
+ Replies use the OpenAI Chat Completions shape, returned as plain dictionaries.
64
+
65
+ ## Already using the OpenAI SDK?
66
+
67
+ FreeTheAI speaks the OpenAI wire format, so the `openai` package works with a different base URL:
68
+
69
+ ```python
70
+ from openai import OpenAI
71
+
72
+ client = OpenAI(base_url="https://api.freetheai.org/v1", api_key="ftai_...")
73
+ ```
74
+
75
+ That gives you the plain client without the handling described on [Reliability](reliability.md).
@@ -0,0 +1,40 @@
1
+ ---
2
+ description: Async usage of the FreeTheAI Python SDK with asyncio.
3
+ ---
4
+
5
+ # Async
6
+
7
+ `AsyncFreeTheAI` has the same options and methods, awaited.
8
+
9
+ ```python
10
+ import asyncio
11
+ from freetheai import AsyncFreeTheAI
12
+
13
+ async def main():
14
+ async with AsyncFreeTheAI() as client:
15
+ reply = await client.chat.completions.create(
16
+ model="fta/zai/glm-5.3",
17
+ messages=[{"role": "user", "content": "Hello!"}],
18
+ )
19
+ print(reply["choices"][0]["message"]["content"])
20
+
21
+ async for text in client.chat.completions.stream_text(
22
+ model="fta/zai/glm-5.3",
23
+ messages=[{"role": "user", "content": "Count to five."}],
24
+ ):
25
+ print(text, end="")
26
+
27
+ asyncio.run(main())
28
+ ```
29
+
30
+ ## Many requests at once
31
+
32
+ Fire as many as you like with `asyncio.gather`. The client learns how many replies your account may run at once and queues the rest, so you don't get concurrency errors:
33
+
34
+ ```python
35
+ questions = ["What is DNS?", "What is TLS?", "What is HTTP/3?"]
36
+ replies = await asyncio.gather(*(
37
+ client.chat.completions.create(model="fta/zai/glm-5.3-flash", messages=[{"role": "user", "content": q}])
38
+ for q in questions
39
+ ))
40
+ ```