Good news for those who are having trouble with the input token count exceeding the limit!
I’ve found a temporary solution.
However, please note that this is not an official solution.
The error discussed in this article
[GoogleGenerativeAI Error]: Error fetching from https://monospace-pa.googleapis.com/v1/models/gemini-2.5-pro-preview-03-25:streamGenerateContent?alt=sse: [400 Bad Request] The input token count (1053137) exceeds the maximum number of tokens allowed (1048576).
Related cases
- Firebase Studio Token Exceeding in Prototyper
- Prototyper Was a Gamechanger — But Context Loss Is a Dealbreaker
- Help Needed: "GoogleGenerativeAI Error" - Token Count Exceeds Limit
Explanation
In this section, I’ll share my understanding of how App Prototyper Agent works based on the tests I’ve done.
Please note that this is only my understanding and is not official information.
The conversation history with App Prototyper Agent seems to be saved in the following location in the workspace.
/home/user/.idx/ai
folder
It contains the following two JSON files, both of which store conversation history, but they seem to have different formats and purposes.
capra-thread.json
Referenced for display in Prototyper and used to allow app creators to check the conversation history.
The contents mainly include the messages interacted, the names of the files modified, and information about restore points.
I verified this by actually deleting the contents of the files.
Even after deleting the contents of the files and refreshing the page, the history remained.
However, after resetting the workspace, I confirmed that the conversation history on Prototyper was deleted.
Furthermore, when I restored the deleted content and reset the workspace, the conversation history reappeared in Prototyper.
(Reference) Workspace reset: Assign a new VM while maintaining the state of the files on the home disk.
capra-context-state.json
This is the context itself that is added to the input of the App prototyper agent prompt.
In addition to this file, code files in the workspace are also used as context for prompt input.
However, folders and files listed in .gitignore
are not used as context for prompt input.
This mainly includes the contents of the initially created App Blueprint and the messages interacted.
Information about files modified by the App Prototyper agent is recorded concisely as follows:
(Omitted from agent history: changes suggested and applied to the following files: /src/ai/flows/generate-recipe-image-flow.ts, /src/ai/dev.ts)
This file is directly referenced only when a new prompt is sent.
When you click [Try Again] to resend the prompt, the capra-context-state.json
file that was referenced when the prompt was first sent is referenced.
As it currently stands, all content in this file (i.e., all conversation history) seems to be added to the prompt each time.
This means that as the conversation history grows, the number of input tokens will continue to increase, eventually causing an input token limit error.
In other words, by reducing the contents of this file, you can reduce the number of input tokens and resolve the input token limit exceeded error.
I was able to resolve the issue for the time being by following the steps described at the bottom of this page, but I strongly recommend that you read the following precautions before proceeding.
Precautions
The current behavior of the App Prototyper agent is as follows:
- Past conversations with the app creator can only be used as a context by referencing
capra-context-state.json
. capra-thread.json
is only for the app creator to view conversation history on Prototyper.
This means that the content of conversations deleted using the following steps will no longer be considered by the App Prototyper agent in the future.
Therefore, please be careful not to delete any conversation history that you consider important for future conversations with the App Prototyper agent.
I recommend deleting the following two types of conversations:
Old messages
General chat AI deletes old conversation history in order when the maximum number of input tokens is exceeded.
user
messages that start with “I see this error” and the model
message immediately following them
These types of messages can become numerous and are often not important in context.
This is recorded when the following events occur:
-
When the app creator clicks [Fix Error] when an error occurs
-
When the App prototyper agent automatically corrects an error in the generated code (Auto-fixed error)
The following two messages are recorded for each error correction:
user
message: A message requesting the app prototyper agent to fix the error- Immediately following
model
message: A message reporting the cause of the error and how the app prototyper agent fixed it
With the above points in mind, carefully select and delete any messages that you believe are not necessary for future conversations with the agent.
How to reduce past conversation history contained in input tokens
Caution
- I strongly recommend that you read the above points before proceeding.
- These steps are not official instructions, so please proceed at your own risk.
Procedure
-
Sign in to Firebase Studio.
-
From [My workspaces], click the workspace where the problem is occurring to open it.
-
Click [Switch to Code] to open the code view.
-
Press [Ctrl+`] to open the terminal (skip if the terminal is already open).
-
Enter the following command in the terminal and press the [Enter] key to execute it, creating backups of the current
capra-context-state.json
andcapra-thread.json
files in thecontext_backup
folder:timestamp=$(date +%Y%m%d%H%M%S); mkdir -p "/home/user/studio/context_backup/" && cp "/home/user/.idx/ai/capra-context-state.json" "/home/user/studio/context_backup/capra-context-state-${timestamp}.json" && cp "/home/user/.idx/ai/capra-thread.json" "/home/user/studio/context_backup/capra-thread-${timestamp}.json"
-
Confirm that the backup has been created in the
context_backup
folder. -
Open
.gitignore
and add the following to the bottom:# prototyper /context_backup
Note: This prevents the
context_backup
folder and the backup files within it from being used as input for the App prototyper agent context. -
Enter the following command in the terminal and press the [Enter] key to open the context file:
code /home/user/.idx/ai/capra-context-state.json
-
Once
capra-context-state.json
is open, right-click on the file and select [Format Document]. -
Verify that the previously single-line
capra-context-state.json
has been formatted into a readable format. -
Locate the line that reads
app-prototyping-agent: edit-app-agent: [
-
Confirm that the conversation history is listed in the range enclosed by
[]
. -
Carefully select messages in the
app-prototyping-agent: edit-app-agent: [<here>]
that you do not need to refer to in future conversations with the agent and delete them as follows:-
Deletion range when deleting a single message
-
Deletion range when deleting a prompt and its response output as a single set (this is considered a more natural deletion)
Causion: Do not delete the entire JSON or any items other than
app-prototyping-agent: edit-app-agent: [<here>]
. If you do this, the App prototyping agent might mistakenly recognize existing workspace as new workspace and attempt to recreate App Blueprint. -
-
Once the deletion is complete, press the [Ctrl+S] keys to ensure that the changes to
capra-context-state.json
are saved. -
Click [Switch to Prototyper] to open the Prototyper view.
-
Send a prompt to the App Prototyper agent and verify that no input token count error occurs.
Instead of clicking [Try Again], be sure to resend the prompt from the input box.Note: As explained in the Explanation >
/home/user/.idx/ai
folder >capra-context-state.json
section, [Try Again] action uses the context data fromcapra-context-state.json
which is before you delete the history, so you should see the same input token limit exceeded error again. -
If an error still occurs at this point, press the [Ctrl+R] key or the [Refresh] icon in your web browser to refresh the page or reset the workspace (your code files will not be deleted) and try again.
-
If the issue persists, further reduce the history from
capra-context-state.json
.
If the number of input tokens mentioned in the error message after doing this step has decreased compared to before, it is highly likely that the large number of entries in the history is the cause, so keep reducing much more entries in the history.
If the issue persists even after following all the above steps, it is likely caused by another issue, so I recommend contacting official support.
If you want to include deleted conversation history in the context again
Retrieve the relevant history from the backup created in step 5 and return it to /home/user/.idx/ai/capra-context-state.json
.
However, this may cause the number of input tokens to exceed the limit again, so if the error occurs again, adjust the size of the history.
Let’s wait for the dev team to implement a permanent solution.
@kirupa, if there are any corrections or additions to the above content, please follow up from you or other official team members.
Unless improvements on the product side are made to adjust the conversation history entered in the prompt, almost all users will eventually encounter this issue.
Therefore, we would like you to address this issue with a high priority.
If this information helps solve your issue, I would be very happy to hear from you