You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5cf16d1
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,19 @@ You can try out RLMs quickly by installing from PyPi:
41
41
pip install rlms
42
42
```
43
43
44
+
> [!IMPORTANT]
45
+
> **Token Limit & Cost Protection**: RLM has a **default limit of 1,000,000 tokens per session** to prevent unexpectedly large bills. This costs approximately:
46
+
> - GPT-3.5 Turbo: ~$1 per session
47
+
> - GPT-4o: ~$6 per session
48
+
> - GPT-4 Turbo: ~$20 per session
49
+
> - Claude Opus: ~$45 per session
50
+
>
51
+
> To change this limit:
52
+
> ```python
53
+
> rlm = RLM(max_tokens=500_000) # Reduce to 500k tokens
54
+
> rlm = RLM(max_tokens=None) # Remove limit (use with caution!)
55
+
>```
56
+
44
57
The default RLM client uses a REPL environment that runs on the host process through Python `exec` calls. It uses the same virtual environment as the host process (i.e. it will have access to the same dependencies), but with some limitations in its available global modules. As an example, we can call RLM completions using GPT-5-nano:
45
58
```python
46
59
from rlm importRLM
@@ -54,6 +67,11 @@ rlm = RLM(
54
67
print(rlm.completion("Print me the first 100 powers of two, each on a newline.").response)
55
68
```
56
69
70
+
**Understanding Your Token Budget:**
71
+
- Each session (one `completion()` call) is limited to 1M tokens by default
72
+
- You can check token usage: `result.usage_summary.to_dict()`
73
+
- Adjust the limit with `max_tokens` parameter (see [Token Limits](#important-token-limit--cost-protection) above)
Copy file name to clipboardExpand all lines: docs/api/rlm.md
+79Lines changed: 79 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,7 @@ RLM(
45
45
depth: int=0,
46
46
max_depth: int=1,
47
47
max_iterations: int=30,
48
+
max_tokens: int|None=None,
48
49
custom_system_prompt: str|None=None,
49
50
other_backends: list[str] |None=None,
50
51
other_backend_kwargs: list[dict] |None=None,
@@ -187,6 +188,83 @@ rlm = RLM(
187
188
188
189
---
189
190
191
+
#### `max_tokens`
192
+
{: .no_toc }
193
+
194
+
**Type:**`int | None`
195
+
**Default:**`1_000_000` (1 million tokens)
196
+
197
+
Maximum total tokens (input + output combined) allowed per `completion()` session. When this limit is reached or exceeded, the session ends early to stay within the token budget.
198
+
199
+
{: .warning }
200
+
> **This is a cost protection feature!** The default limit prevents unexpectedly large API bills.
201
+
202
+
**Cost implications of 1M tokens:**
203
+
204
+
| Model | Cost for 1M Tokens |
205
+
|:------|:-------------------|
206
+
| GPT-3.5 Turbo |~$1 |
207
+
| GPT-4o |~$6 |
208
+
| GPT-4o-mini |~$0.30 |
209
+
| GPT-4 Turbo |~$20 |
210
+
| Claude Sonnet 4 |~$9 |
211
+
| Claude Opus |~$45 |
212
+
213
+
**Token counting:**
214
+
- Includes all LM calls (main model + sub-LM calls via `llm_query()`)
215
+
- Tracks cumulative usage across all iterations in a single session
216
+
- Resets for each new `completion()` call (even in persistent mode)
217
+
218
+
**Examples:**
219
+
220
+
```python
221
+
# Use default 1M token limit (recommended for most use cases)
222
+
rlm = RLM(
223
+
backend="openai",
224
+
backend_kwargs={"model_name": "gpt-4o"},
225
+
# max_tokens=1_000_000 is implicit
226
+
)
227
+
228
+
# Reduce limit for stricter budget control
229
+
rlm = RLM(
230
+
backend="openai",
231
+
backend_kwargs={"model_name": "gpt-4o"},
232
+
max_tokens=100_000, # Limit to ~$0.60 per session
233
+
)
234
+
235
+
# Increase limit for complex, expensive tasks
236
+
rlm = RLM(
237
+
backend="openai",
238
+
backend_kwargs={"model_name": "gpt-4o"},
239
+
max_tokens=5_000_000, # Allow up to ~$30 per session
240
+
)
241
+
242
+
# Remove limit entirely (not recommended - use with caution!)
243
+
rlm = RLM(
244
+
backend="openai",
245
+
backend_kwargs={"model_name": "gpt-4o"},
246
+
max_tokens=None, # Unlimited - can result in large bills!
247
+
)
248
+
249
+
result = rlm.completion("Analyze this dataset...")
0 commit comments