Spaces:
Running
Running
| """List all Gemini models on this API key that support bidiGenerateContent. | |
| These are the models you can put in GEMINI_LIVE_MODEL. Anything not listed | |
| here will 1008 at connect time. | |
| Use: | |
| GEMINI_API_KEY=... /venvs/apps_venv/bin/python scripts/list_gemini_live_models.py | |
| """ | |
| from __future__ import annotations | |
| import os | |
| import sys | |
| import httpx | |
| def main() -> int: | |
| key = os.environ.get("GEMINI_API_KEY", "").strip() | |
| if not key: | |
| print("ERROR: GEMINI_API_KEY not set", file=sys.stderr) | |
| return 1 | |
| url = f"https://generativelanguage.googleapis.com/v1beta/models?key={key}&pageSize=200" | |
| try: | |
| resp = httpx.get(url, timeout=15.0) | |
| resp.raise_for_status() | |
| except Exception as e: | |
| print(f"ERROR: {e}", file=sys.stderr) | |
| return 1 | |
| data = resp.json() | |
| models = data.get("models", []) | |
| live_models = [] | |
| for m in models: | |
| methods = m.get("supportedGenerationMethods") or [] | |
| if "bidiGenerateContent" in methods: | |
| live_models.append(m.get("name", "?").replace("models/", "")) | |
| if not live_models: | |
| print("(no Live-capable models on this key)") | |
| return 0 | |
| print(f"Live-capable models on this key ({len(live_models)}):\n") | |
| for name in sorted(live_models): | |
| print(f" {name}") | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |