A Python project that transforms model data from various API providers (OpenRouter, Requesty) into the OpenCode configuration format. This project enables seamless integration of third-party AI models into the OpenCode ecosystem by standardizing their metadata and capabilities.
The OpenCode Models Transformer project provides utilities to convert model specifications from different providers into a unified format that conforms to the OpenCode configuration schema. This ensures consistent model representation and enables proper integration with OpenCode's agent system.
- Multi-Provider Support: Currently supports OpenRouter and Requesty API providers
- Schema Validation: Transforms models to conform to the OpenCode configuration schema
- Capability Mapping: Automatically detects and maps model capabilities (vision, reasoning, tool calling, etc.)
- Cost Conversion: Standardizes pricing information to per-million token format
- Flexible Filtering: Allows transformation of specific models or entire catalogs
- Command Line Interface: Easy-to-use CLI for batch transformations
opencode_models/
├── open_code_config_schema.json # OpenCode configuration schema
├── openrouter_model_transformer.py # OpenRouter transformation logic
├── requesty_model_transformer.py # Requesty transformation logic
├── transform_openrouter_models.py # OpenRouter transformation script
├── transform_requesty_models.py # Requesty transformation script
├── example_usage.py # Example usage demonstration
├── openrouter_models_list.json # OpenRouter models database
├── requesty_models_list.json # Requesty models database
├── openrouter_models_opencode_ready.json # Transformed OpenRouter models
└── requesty_models_opencode_ready.json # Transformed Requesty models
- Python 3.7+
- No external dependencies (uses only Python standard library)
# Transform all OpenRouter models
python openrouter_model_transformer.py openrouter_models_list.json openrouter_output.json
# Transform specific models
python openrouter_model_transformer.py openrouter_models_list.json openrouter_output.json --models google/gemini-2.5-flash anthropic/claude-sonnet-4# Transform all Requesty models
python requesty_model_transformer.py requesty_models_list.json requesty_output.json
# Transform specific models
python requesty_model_transformer.py requesty_models_list.json requesty_output.json --models deepinfra/Qwen/Qwen3-Coder-480B-A35B-Instruct# Transform predefined OpenRouter models
python transform_openrouter_models.py
# Transform predefined Requesty models
python transform_requesty_models.pyfrom openrouter_model_transformer import transform_models, save_transformed_models
# Transform models
transformed = transform_models('input.json', ['google/gemini-2.5-flash'])
# Save results
save_transformed_models(transformed, 'output.json')The transformation process converts provider-specific model data into the OpenCode format by:
- Extracting Core Properties: ID, name, release dates
- Mapping Capabilities: Vision support, reasoning, tool calling, temperature control
- Standardizing Limits: Context window and output token limits
- Converting Pricing: Normalizing costs to per-million tokens
- Determining Modalities: Input/output types (text, image)
- Applying Schema Compliance: Ensuring output matches OpenCode configuration schema
- Basic Info: ID, name, release/update dates
- Capabilities: File attachment, reasoning, temperature, tool calling
- Limits: Context window, maximum output tokens
- Modalities: Supported input/output types (text, image)
- Pricing: Input/output costs per million tokens (including cache costs)
- Options: Extensible configuration object
The transformed models follow the OpenCode configuration schema:
{
"provider": {
"models": {
"model-id": {
"id": "provider/model-name",
"name": "Display Name",
"release_date": "2024-01-01",
"last_updated": "2024-01-01",
"attachment": true,
"reasoning": false,
"temperature": true,
"tool_call": true,
"limit": {
"context": 1048576,
"output": 65535
},
"modalities": {
"input": ["text", "image"],
"output": ["text"]
},
"cost": {
"input": 0.3,
"output": 2.5,
"cache_read": 0.075,
"cache_write": 0.383
},
"options": {}
}
}
}
}The project conforms to the OpenCode configuration schema defined in open_code_config_schema.json. This schema ensures that transformed models are compatible with OpenCode's configuration system and can be properly integrated into the platform.
See example_usage.py for comprehensive examples of how to use the transformers programmatically, including filtering specific models and handling different input formats.
To add support for new providers:
- Create a new transformer module following the existing pattern
- Implement the
transform_models()andsave_transformed_models()functions - Map provider-specific fields to OpenCode schema properties
- Add CLI support and example usage
- Update this README with provider-specific instructions
This project is licensed under the terms specified in the LICENSE file.