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
Copy file name to clipboardExpand all lines: content/copilot/concepts/billing/usage-based-billing-for-individuals.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,6 +81,8 @@ More complex interactions consume more of your usage allowance. The main factors
81
81
82
82
> [!NOTE] {% data reusables.copilot.auto-model-discount %}
83
83
84
+
For guidance on how to optimize your usage and reduce spend, including how to set session limits to cap spend for agent tasks, see [AUTOTITLE](/copilot/tutorials/optimize-ai-usage).
85
+
84
86
## What happens if I exceed my included {% data variables.product.prodname_ai_credits_short %}?
85
87
86
88
When your {% data variables.product.prodname_ai_credits_short %} are exhausted, you can:
Copy file name to clipboardExpand all lines: content/copilot/how-tos/copilot-cli/cli-best-practices.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -124,6 +124,12 @@ You can configure {% data variables.copilot.copilot_cli_short %} to use your own
124
124
125
125
See [Using your own model provider](/copilot/concepts/agents/copilot-cli/about-copilot-cli#using-your-own-model-provider).
126
126
127
+
### Set {% data variables.product.prodname_ai_credit_singular %} session limits
128
+
129
+
You can cap the amount of {% data variables.product.prodname_ai_credits_short %} that {% data variables.product.prodname_copilot_short %} can spend on a single session so that long-running or complex tasks don't consume more resources than you expect. See [AUTOTITLE](/copilot/how-tos/copilot-cli/use-copilot-cli/set-session-limit).
130
+
131
+
For more information on how to optimize your {% data variables.product.prodname_ai_credits_short %} usage generally, see [AUTOTITLE](/copilot/tutorials/optimize-ai-usage).
title: Setting an {% data variables.product.prodname_ai_credit_singular %} session limit in {% data variables.copilot.copilot_cli %}
3
+
shortTitle: Set an {% data variables.product.prodname_ai_credit_singular %} limit
4
+
allowTitleToDifferFromFilename: true
5
+
intro: 'Limit the amount of {% data variables.product.prodname_ai_credits_short %} {% data variables.product.prodname_copilot_short %} can spend on a session to control costs and keep tasks predictable.'
6
+
versions:
7
+
feature: copilot
8
+
contentType: how-tos
9
+
category:
10
+
- Build with Copilot CLI
11
+
docsTeamMetrics:
12
+
- copilot-cli
13
+
---
14
+
15
+
> [!NOTE]
16
+
> {% data variables.product.prodname_ai_credit_singular %} session limits are currently in {% data variables.release-phases.public_preview %} and subject to change.
17
+
18
+
An {% data variables.product.prodname_ai_credit_singular %} session limit caps the amount of {% data variables.product.prodname_ai_credits %} that {% data variables.product.prodname_copilot_short %} can spend in a session.
19
+
20
+
{% data variables.product.prodname_ai_credits_short %} are the unit {% data variables.product.prodname_copilot_short %} uses to track the cost of AI model interactions: each credit equals {% data variables.product.prodname_ai_credits_value %}, and usage depends on the model and the number of tokens consumed.
21
+
22
+
When you set an {% data variables.product.prodname_ai_credit_singular %} session limit for {% data variables.product.prodname_copilot_short %}, instead of running until the task is done or until you intervene, {% data variables.product.prodname_copilot_short %} stops when it hits the limit and gives you the option to reset or adjust it.
23
+
24
+
These session limits are **soft limits**. If a response is in progress when the limit is reached, that response completes before the session stops, so actual usage may slightly exceed the configured number.
25
+
26
+
## Setting an {% data variables.product.prodname_ai_credit_singular %} session limit
27
+
28
+
How the limit is set and applied depends on whether you are in an interactive session or running the CLI programmatically.
29
+
30
+
> [!TIP]
31
+
> {% data variables.product.prodname_ai_credit_singular %} session limits work best when set to > 30 {% data variables.product.prodname_ai_credits_short %} as most model calls will cost more than 20 {% data variables.product.prodname_ai_credits_short %}.
32
+
33
+
### Setting a limit within an interactive session
34
+
35
+
In an interactive CLI session, the limit applies for the entire session and depletes as each message is processed, independent of how many messages you send. When the limit is reached, you are prompted to reset it.
36
+
37
+
To set your session limit, use `/limits set`.
38
+
39
+
```copilot copy
40
+
/limits set max-ai-credits NUMBER
41
+
```
42
+
43
+
To remove the limit, enter:
44
+
45
+
```copilot copy
46
+
/limits unset
47
+
```
48
+
49
+
### Setting a limit in non-interactive mode
50
+
51
+
When you run {% data variables.copilot.copilot_cli_short %} programmatically from the command line, the limit applies for the duration of {% data variables.product.prodname_copilot_short %}'s work on the task and remains active until {% data variables.product.prodname_copilot_short %} finishes responding.
52
+
53
+
To set a limit, pass `--max-ai-credits=NUMBER`.
54
+
55
+
```bash copy
56
+
copilot -p "YOUR PROMPT" --max-ai-credits NUMBER
57
+
```
58
+
59
+
## What happens when the limit is reached
60
+
61
+
When the limit is hit, the agent stops cleanly and lets you know.
62
+
63
+
***In interactive mode**, you are prompted to reset the limit. You can use `/limits set` to raise the limit and continue your session from where the agent stopped.
64
+
***In non-interactive mode**, the run ends when the limit is reached.
*[What are {% data variables.product.prodname_ai_credits %}](/copilot/concepts/billing/usage-based-billing-for-individuals#what-are--data-variablesproductprodname_ai_credits-)
Copy file name to clipboardExpand all lines: content/copilot/how-tos/manage-and-track-spending/monitor-ai-usage.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,3 +49,8 @@ You can access usage information in the following IDEs.
49
49
***In JetBrains IDEs**, click the {% data variables.product.prodname_copilot_short %} icon ({% octicon "copilot" aria-hidden="true" aria-label="copilot" %}) in the status bar, then select **View quota usage**.
50
50
***In Xcode**, click the {% data variables.product.prodname_copilot_short %} icon ({% octicon "copilot" aria-hidden="true" aria-label="copilot" %}) in the menu bar.
51
51
***In Eclipse**, click the {% data variables.product.prodname_copilot_short %} icon ({% octicon "copilot" aria-hidden="true" aria-label="copilot" %}) in the status bar at the bottom of Eclipse.
52
+
53
+
## Next steps
54
+
55
+
* For guidance on how to optimize your usage and reduce spend, including how to set session limits to cap spend for agent tasks, see [AUTOTITLE](/copilot/tutorials/optimize-ai-usage).
56
+
* To set up a personal budget for your overall consumption of {% data variables.product.prodname_ai_credits %}, see [AUTOTITLE](/billing/how-tos/set-up-budgets#managing-budgets-for-your-personal-account).
Copy file name to clipboardExpand all lines: content/copilot/tutorials/optimize-ai-usage.md
+18-3Lines changed: 18 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -110,7 +110,22 @@ However, the following actions invalidate the cache, causing the full context to
110
110
***Coming back to an old session**. Caches expire after a period of inactivity (24 hours for OpenAI models and 1 hour for most others). If you've been away a while, start a new session, or run `/compact` (in {% data variables.copilot.copilot_cli_short %}) so what gets rebuilt is a short summary rather than the full history.
111
111
***Changing reasoning mid-session**. Changing the reasoning effort level, context size, or the set of enabled tools and MCP servers during a session invalidates the cache. Configure these settings before you start and leave them unchanged for the session.
112
112
113
-
## 5. Research, plan, then implement
113
+
## 5. Set {% data variables.product.prodname_ai_credit_singular %} session limits
114
+
115
+
An {% data variables.product.prodname_ai_credit_singular %} session limit caps the amount of work {% data variables.product.prodname_copilot_short %} performs on a single session.
116
+
117
+
In {% data variables.copilot.copilot_cli_short %} and {% data variables.copilot.copilot_sdk_short %}, you can set a session limit before initiating a task and when the limit is reached, the agent stops cleanly, notifies you, and lets you choose whether to continue or raise the limit.
118
+
119
+
{% data variables.product.prodname_ai_credit_singular %} session limits are most useful when:
120
+
121
+
* You want to cap {% data variables.product.prodname_ai_credits_short %} usage on a single session to avoid unexpected costs.
122
+
* You're tuning agent efficiency and want to find the minimum {% data variables.product.prodname_ai_credits_short %} that still produces a good result.
123
+
124
+
Session limits are soft limits that help you control how many {% data variables.product.prodname_ai_credits_short %} any single task consumes, but they don't replace user-level budgets or spending limits, which govern your overall monthly consumption. For those controls, see [AUTOTITLE](/copilot/concepts/billing/budgets-for-usage-based-billing).
125
+
126
+
For information on how to set a session limit in {% data variables.copilot.copilot_cli_short %}, see [AUTOTITLE](/copilot/how-tos/copilot-cli/use-copilot-cli/set-session-limit).
127
+
128
+
## 6. Research, plan, then implement
114
129
115
130
One of the biggest shifts in working effectively with agents is moving away from doing everything in a single session. When research, planning, and implementation all happen together, context grows quickly and irrelevant information accumulates.
116
131
@@ -124,7 +139,7 @@ Break work into clear phases:
124
139
125
140
Starting a new session between phases prevents you from carrying unnecessary context forward, which can increase token usage and reduce clarity for the agent. Each phase should operate with only what it needs. For guidance on scoping sessions effectively, see [AUTOTITLE](/copilot/tutorials/cloud-agent/get-the-best-results).
126
141
127
-
## 6. Utilize learnings to be more efficient at every turn
142
+
## 7. Utilize learnings to be more efficient at every turn
128
143
129
144
### Use `/chronicle` to generate insights
130
145
@@ -164,7 +179,7 @@ Persistent instructions improve consistency across agent interactions, but their
164
179
165
180
Keep instructions updated as your codebase, architecture, standards, and workflows evolve. Because these instructions are included in the agent's context on every run, even small improvements can reduce repeated errors and lower wasted token usage over time.
166
181
167
-
## 7. Add deterministic guardrails
182
+
## 8. Add deterministic guardrails
168
183
169
184
Agents are non-deterministic and won't be correct every time, especially in multi-step workflows. Without guardrails, small errors can compound quickly: agents build on incorrect outputs, drift further from the goal, and make debugging more expensive and time-consuming.
0 commit comments