{"id":31727634,"url":"https://github.com/thiswillbeyourgithub/openrouter_cost_into_langfuse","last_synced_at":"2025-10-09T06:29:31.326Z","repository":{"id":316724911,"uuid":"1059530213","full_name":"thiswillbeyourgithub/openrouter_cost_into_langfuse","owner":"thiswillbeyourgithub","description":"A Python script to sync model pricing from OpenRouter to Langfuse's pricing page automatically.","archived":false,"fork":false,"pushed_at":"2025-09-26T09:06:05.000Z","size":20,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-26T11:18:04.649Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thiswillbeyourgithub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-18T15:09:40.000Z","updated_at":"2025-09-26T09:06:08.000Z","dependencies_parsed_at":"2025-09-26T11:18:09.046Z","dependency_job_id":"6bca5c64-30f4-4f83-90a8-023a8ace9787","html_url":"https://github.com/thiswillbeyourgithub/openrouter_cost_into_langfuse","commit_stats":null,"previous_names":["thiswillbeyourgithub/openrouter_cost_into_langfuse"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/thiswillbeyourgithub/openrouter_cost_into_langfuse","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiswillbeyourgithub%2Fopenrouter_cost_into_langfuse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiswillbeyourgithub%2Fopenrouter_cost_into_langfuse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiswillbeyourgithub%2Fopenrouter_cost_into_langfuse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiswillbeyourgithub%2Fopenrouter_cost_into_langfuse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thiswillbeyourgithub","download_url":"https://codeload.github.com/thiswillbeyourgithub/openrouter_cost_into_langfuse/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiswillbeyourgithub%2Fopenrouter_cost_into_langfuse/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000825,"owners_count":26082950,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-09T06:29:28.629Z","updated_at":"2025-10-09T06:29:31.317Z","avatar_url":"https://github.com/thiswillbeyourgithub.png","language":"Python","readme":"# OpenRouter to Langfuse Model Pricing Sync\n\n[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)\n\nA Python script that automatically syncs model pricing data from OpenRouter to Langfuse's pricing page. This tool fetches the latest pricing information from OpenRouter's API and creates corresponding models in Langfuse with accurate pricing data.\n\nYou might also be interested in my other script: [LiteLLM Proxy OpenRouter Price Updater](https://github.com/thiswillbeyourgithub/litellm_proxy_openrouter_price_updater).\n\nThis script was created with assistance from [aider.chat](https://github.com/Aider-AI/aider/).\n\n## Features\n\n- 🔄 **Automatic Sync**: Fetches pricing data from OpenRouter and creates models in Langfuse\n- 🧹 **Clean Management**: Automatically deletes previously created models before adding new ones\n- 🏃 **Continuous Operation**: Safe to run repeatedly - handles updates gracefully\n- 🔍 **Dry Run Mode**: Test operations without making actual changes\n- 🗑️ **Reset Mode**: Option to only delete script-managed models without creating new ones\n- ⚡ **Rate Limiting**: Built-in rate limiting to respect API limits\n- 📊 **Progress Tracking**: Visual progress bars and detailed logging\n- 🔧 **Flexible Configuration**: Environment variables or CLI arguments\n\n## Compatibility\n\n- ✅ Tested with **Langfuse v3**\n- 🐍 Python 3.7+\n\n## Installation\n\n1. Clone this repository:\n```bash\ngit clone \u003crepository-url\u003e\ncd \u003crepository-name\u003e\n```\n\n2. Install required dependencies:\n```bash\npip install click requests tqdm loguru\n```\n\n## Configuration\n\nThe script requires Langfuse credentials to sync models. You can provide these via environment variables or CLI arguments.\n\n### Environment Variables\n\n```bash\nexport LANGFUSE_PUBLIC_KEY=\"your_public_key\"\nexport LANGFUSE_SECRET_KEY=\"your_secret_key\"\nexport LANGFUSE_HOST=\"https://your-langfuse-instance.com\"\n```\n\n### CLI Arguments\n\nAlternatively, pass credentials directly:\n```bash\npython script.py --langfuse-public-key=\"your_key\" --langfuse-secret-key=\"your_secret\" --langfuse-host=\"https://your-instance.com\"\n```\n\n## Usage\n\n### Basic Sync\nSync all OpenRouter models to Langfuse:\n```bash\npython script.py\n```\n\n### Dry Run\nTest the sync without making actual changes:\n```bash\npython script.py --dry\n```\n\n### Reset Mode\nDelete only the script-managed models (useful for cleanup):\n```bash\npython script.py --reset\n```\n\n### Custom Start Date\nSet a specific start date for model pricing (dd-mm-yyyy format):\n```bash\npython script.py --start-date=\"01-12-2024\"\n```\n\n### Rate Limiting\nAdd delays between API calls to respect rate limits:\n```bash\npython script.py --rate-limit-delay=0.5\n```\n\n## How It Works\n\n1. **Fetch Data**: Retrieves current model pricing from OpenRouter API\n2. **Clean Slate**: Identifies and deletes previously created models (those starting with `openrouter_script_`)\n3. **Create Models**: Creates new Langfuse models with current pricing data\n4. **Smart Naming**: Handles duplicate model names and special cases (e.g., \"thinking\" models)\n5. **Tokenizer Detection**: Automatically assigns appropriate tokenizers based on model provider\n\n## Model Management\n\nThe script creates models in Langfuse with:\n- **Naming Pattern**: `openrouter_script_{canonical_slug}`\n- **Match Pattern**: Regex to match the OpenRouter model ID\n- **Pricing**: Input/output token prices from OpenRouter\n- **Tokenizer**: Automatically selected (Claude for Anthropic models, OpenAI for others)\n\n### Model Identification\n\nScript-managed models are identified by:\n- Model name starts with `openrouter_script_`\n- `isLangfuseManaged` is set to `False`\n\nThis ensures the script only manages its own models and won't interfere with manually created ones.\n\n## Command Line Options\n\n| Option | Description | Default |\n|--------|-------------|---------|\n| `--langfuse-public-key` | Langfuse public key | From `LANGFUSE_PUBLIC_KEY` env var |\n| `--langfuse-secret-key` | Langfuse secret key | From `LANGFUSE_SECRET_KEY` env var |\n| `--langfuse-host` | Langfuse host URL | From `LANGFUSE_HOST` env var |\n| `--dry` | Dry run mode (no actual changes) | `False` |\n| `--reset` | Only delete script-managed models | `False` |\n| `--start-date` | Start date for models (dd-mm-yyyy) | Today's date |\n| `--rate-limit-delay` | Delay between API calls (seconds) | `0` |\n\n## Logging\n\nThe script creates detailed logs in `script.log` with:\n- Automatic rotation (10 MB files)\n- 7-day retention\n- INFO level and above\n\n## Continuous Operation\n\nThis script is designed for continuous operation:\n\n- **Safe Re-runs**: Each execution cleans up its previous models before creating new ones\n- **No Conflicts**: Only manages models it created (identified by naming pattern)\n- **Incremental Updates**: Handles pricing changes and new models automatically\n\nYou can safely run this script on a schedule (e.g., daily) to keep your Langfuse pricing data up-to-date with OpenRouter.\n\n## Error Handling\n\n- **API Failures**: Graceful handling of network issues and API errors\n- **Rate Limiting**: Built-in delays to respect API limits\n- **Data Validation**: Skips models with missing or invalid pricing data\n- **Detailed Logging**: Comprehensive error reporting and debugging information\n\n## Contributing\n\nIssues and pull requests are welcome! Please feel free to:\n\n- 🐛 Report bugs\n- 💡 Suggest new features\n- 🔧 Submit improvements\n- 📖 Improve documentation\n\n## License\n\nThis project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details.\n\n## Acknowledgments\n\n- Created with assistance from [aider.chat](https://github.com/Aider-AI/aider/)\n- Uses [OpenRouter API](https://openrouter.ai/docs) for model pricing data\n- Integrates with [Langfuse](https://langfuse.com/) for LLM observability and pricing management\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiswillbeyourgithub%2Fopenrouter_cost_into_langfuse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthiswillbeyourgithub%2Fopenrouter_cost_into_langfuse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiswillbeyourgithub%2Fopenrouter_cost_into_langfuse/lists"}