Skip to content

AngryBearr/opencode_models

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenCode Models Transformer

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.

Overview

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.

Features

  • 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

Project Structure

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

Installation & Usage

Prerequisites

  • Python 3.7+
  • No external dependencies (uses only Python standard library)

Basic Usage

Transform OpenRouter Models

# 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 Requesty Models

# 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

Use Provided Scripts

# Transform predefined OpenRouter models
python transform_openrouter_models.py

# Transform predefined Requesty models
python transform_requesty_models.py

Programmatic Usage

from 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')

Transformation Process

The transformation process converts provider-specific model data into the OpenCode format by:

  1. Extracting Core Properties: ID, name, release dates
  2. Mapping Capabilities: Vision support, reasoning, tool calling, temperature control
  3. Standardizing Limits: Context window and output token limits
  4. Converting Pricing: Normalizing costs to per-million tokens
  5. Determining Modalities: Input/output types (text, image)
  6. Applying Schema Compliance: Ensuring output matches OpenCode configuration schema

Model Properties Mapped

  • 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

Output Format

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": {}
      }
    }
  }
}

Configuration Schema

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.

Examples

See example_usage.py for comprehensive examples of how to use the transformers programmatically, including filtering specific models and handling different input formats.

Contributing

To add support for new providers:

  1. Create a new transformer module following the existing pattern
  2. Implement the transform_models() and save_transformed_models() functions
  3. Map provider-specific fields to OpenCode schema properties
  4. Add CLI support and example usage
  5. Update this README with provider-specific instructions

License

This project is licensed under the terms specified in the LICENSE file.

About

Opencode python scripts models transformers.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages