Last active
May 15, 2026 16:09
-
-
Save m13253/40a8f5255c1994ce813317767c61420d to your computer and use it in GitHub Desktop.
Convert Copilot Gateway model list to OpenCode and Zed settings file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # Usage: | |
| # curl -H 'Authorization: Bearer <TOKEN>' http://localhost:8000/v1/models | ./copilot-gateway-to-zed.py | |
| import json | |
| import sys | |
| def main() -> None: | |
| print( | |
| "{\n" | |
| ' "$schema": "https://opencode.ai/config.json",\n' | |
| ' "provider": {\n' | |
| ' "copilot-gateway": {\n' | |
| ' "name": "Copilot Gateway",\n' | |
| ' "npm": "@ai-sdk/openai-compatible",\n' | |
| ' "options": {\n' | |
| ' "baseURL": "http://localhost:8000/v1" // https://github.com/Menci/copilot-gateway\n' | |
| " },\n" | |
| ' "models": ', | |
| end="", | |
| ) | |
| print( | |
| json.dumps( | |
| { | |
| model["id"]: { | |
| "id": model["id"], | |
| "name": model["name"], | |
| "family": model["capabilities"]["family"], | |
| "reasoning": len( | |
| model["capabilities"]["supports"].get("reasoning_effort", []) | |
| ) | |
| != 0, | |
| "tool_call": model["capabilities"]["supports"]["tool_calls"], | |
| "limit": { | |
| "context": model["capabilities"]["limits"][ | |
| "max_context_window_tokens" | |
| ], | |
| "output": model["capabilities"]["limits"]["max_output_tokens"], | |
| }, | |
| "modalities": { | |
| "input": ["text"] | |
| + ( | |
| ["image"] | |
| if model["capabilities"]["supports"].get("vision", False) | |
| else [] | |
| ), | |
| "output": ["text"], | |
| }, | |
| } | |
| for model in json.load(sys.stdin.buffer)["data"] | |
| if model["capabilities"]["type"] == "chat" | |
| and model["model_picker_enabled"] | |
| }, | |
| ensure_ascii=False, | |
| indent=2, | |
| ).replace("\n", "\n ") | |
| ) | |
| print(" }\n }\n}") | |
| if __name__ == "__main__": | |
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # Usage: | |
| # curl -H 'Authorization: Bearer <TOKEN>' http://localhost:8000/v1/models | ./copilot-gateway-to-zed.py | |
| import json | |
| import sys | |
| def main() -> None: | |
| print( | |
| "// Zed settings\n" | |
| "//\n" | |
| "// For information on how to configure Zed, see the Zed\n" | |
| "// documentation: https://zed.dev/docs/configuring-zed\n" | |
| "{\n" | |
| ' "language_models": {\n' | |
| ' "openai_compatible": {\n' | |
| ' "Copilot Gateway": {\n' | |
| ' "api_url": "http://localhost:8000/v1", // https://github.com/Menci/copilot-gateway\n' | |
| ' "available_models": ', | |
| end="", | |
| ) | |
| print( | |
| json.dumps( | |
| [ | |
| { | |
| "name": model["id"], | |
| "display_name": model["name"], | |
| "max_tokens": model["capabilities"]["limits"][ | |
| "max_context_window_tokens" | |
| ], | |
| "max_output_tokens": model["capabilities"]["limits"][ | |
| "max_output_tokens" | |
| ], | |
| "max_completion_tokens": model["capabilities"]["limits"][ | |
| "max_output_tokens" | |
| ], | |
| "capabilities": { | |
| "tools": model["capabilities"]["supports"]["tool_calls"], | |
| "images": model["capabilities"]["supports"].get( | |
| "vision", False | |
| ), | |
| "parallel_tool_calls": model["capabilities"]["supports"].get( | |
| "parallel_tool_calls", False | |
| ), | |
| "prompt_cache_key": True, | |
| }, | |
| } | |
| for model in json.load(sys.stdin.buffer)["data"] | |
| if model["capabilities"]["type"] == "chat" | |
| and model["model_picker_enabled"] | |
| ], | |
| ensure_ascii=False, | |
| indent=2, | |
| ).replace("\n", "\n ") | |
| ) | |
| print(" }\n }\n }\n}") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment