{"slug": "gemini-interactions-api-vs-stateless-image-gen", "title": "Gemini Interactions API vs. Stateless Image Gen", "summary": "A developer has deployed a Gemini Interactions API server that maintains visual context across image edits using an interaction_id, enabling iterative refinement without re-describing the entire scene. The FastMCP server exposes four tools to the Codex agent, chaining new interaction IDs each turn while locking the aspect ratio after the first generation to prevent quality degradation. The implementation avoids unsupported thinking levels (minimal, medium) that trigger HTTP 400 errors with the gemini-3.1-flash-lite-image model.", "body_md": "# Gemini Interactions API vs. Stateless Image Gen\n\n`gemini-3.1-flash-lite-image`\n\nmodel (NB2Lite) wrapped in a Model Context Protocol (MCP) server for Codex.The core advantage here is the Interactions API. Instead of treating every request as a fresh start, it uses an `interaction_id`\n\nto maintain visual context server-side. When you request an edit, you pass the previous ID, and the model modifies the existing canvas rather than hallucinating a new version of the scene. This turns a \"re-describe everything\" process into a simple \"add a neon sign here\" command.\n\n## Technical Implementation: MCP and Codex\n\nTo get this working as an AI workflow, the setup uses a FastMCP server that exposes four specific tools to the agent. This allows the coding agent to handle image generation and iterative refinement as native skills.\n\nThe logic follows a specific state loop:\n\n1. Initial call via `client.interactions.create`\n\nwith `store=True`\n\n.\n\n2. The API returns an `interaction_id`\n\n.\n\n3. Subsequent edits reference the latest `interaction_id`\n\nto maintain pixel continuity.\n\n## Deployment Details & Gotchas\n\nFrom a real-world deployment perspective, there are a few technical constraints that are easy to miss if you're building from scratch:\n\n**ID Chaining:** Every turn generates a*new*interaction ID. You must chain the most recent one; using an older ID effectively \"forks\" the image state, which can lead to inconsistent results.**Aspect Ratio Lock:** The ratio (1:1, 16:9, etc.) is set at the first generation. Trying to change this during a stateful edit typically degrades the image quality, so the toolset locks the ratio after the first call.**Thinking Levels:** The API supports`low`\n\n(fast) and`high`\n\n(complex). While the documentation mentions`minimal`\n\nand`medium`\n\n, these often trigger HTTP 400 errors with this specific model, so the server is configured to ignore them.\n\nBy packaging this as an MCP server, the integration into the development environment is seamless. The agent knows exactly when to call the image tool and how to manage the session IDs without the user manually tracking strings.\n\n[Next Bash Error Handling: A Practical Guide →](/en/threads/2398/)\n\n## All Replies （4）\n\n[@PatFounder](/en/users/PatFounder/)Pretty sure it's still global. I've been waiting for local masking to actually be viable.", "url": "https://wpnews.pro/news/gemini-interactions-api-vs-stateless-image-gen", "canonical_source": "https://promptcube3.com/en/threads/2412/", "published_at": "2026-07-23 16:03:15+00:00", "updated_at": "2026-07-24 00:36:51.970125+00:00", "lang": "en", "topics": ["generative-ai", "ai-tools", "developer-tools", "artificial-intelligence"], "entities": ["Gemini Interactions API", "FastMCP", "Codex", "gemini-3.1-flash-lite-image", "Model Context Protocol"], "alternates": {"html": "https://wpnews.pro/news/gemini-interactions-api-vs-stateless-image-gen", "markdown": "https://wpnews.pro/news/gemini-interactions-api-vs-stateless-image-gen.md", "text": "https://wpnews.pro/news/gemini-interactions-api-vs-stateless-image-gen.txt", "jsonld": "https://wpnews.pro/news/gemini-interactions-api-vs-stateless-image-gen.jsonld"}}