Skip to content

Instantly share code, notes, and snippets.

@jason-curtis
Last active October 10, 2025 00:30
Show Gist options
  • Select an option

  • Save jason-curtis/68203e61056a8810a7eb74c942bc28e1 to your computer and use it in GitHub Desktop.

Select an option

Save jason-curtis/68203e61056a8810a7eb74c942bc28e1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env -S uv run --quiet --script
# /// script
# dependencies = ["httpx", "python-dotenv"]
# ///
"""
Minimal reproduction of Gemini schema depth issue.
Issue: https://github.com/googleapis/js-genai/issues/882
Reproduces "too many states" error with nested arrays that have maxItems.
"""
import json
import os
import httpx
from dotenv import load_dotenv
load_dotenv() # OPENROUTER_API_KEY must be set
response = httpx.post(
"https://openrouter.ai/api/v1/chat/completions",
headers={
"Authorization": f"Bearer {os.getenv('OPENROUTER_API_KEY')}",
"Content-Type": "application/json",
},
json={
"model": "google/gemini-2.5-flash-lite",
"messages": [{"role": "user", "content": "Extract data from this text"}],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "extract",
"strict": True,
"schema": {
"type": "object",
"properties": {
"entities": {
"type": "array",
"maxItems": 50,
"items": {
"type": "object",
"properties": {
"emails": {
"type": "array",
"items": {"type": "string"},
"maxItems": 10,
}
},
},
}
},
"required": ["entities"],
},
},
},
},
timeout=60,
)
print(json.dumps(response.json(), indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment