选项
首页首页 Skill 开发运营和 CI/CD openrouter-upgrade-migration

安全地迁移和升级 OpenRouter SDK 版本。在更新依赖项或迁移配置时使用。 可通过“openrouter upgrade”、“openrouter migration”、“update openrouter”、“openrouter breaking changes”等短语触发。

...展开全部
49
更新时间 2026-07-01

关于openrouter-upgrade-migration

“openrouter-upgrade-migration ”技能旨在简化 OpenRouter SDK 版本的升级和迁移流程。它解决了更新依赖项时常见的难题,确保开发人员能够安全地实施版本更新并管理配置迁移,同时避免引入破坏性变更。 该技能在执行例行更新或应对新版 SDK 中的破坏性变更时尤为有用,为在升级过程中保持兼容性提供了一种系统化的方法。

该技能提供了一套用于管理 SDK 版本升级的全面工具,涵盖从验证先决条件到确保成功集成的全过程。 主要功能包括轻松迁移配置、处理破坏性变更以及验证迁移后的 API 连接性。它与版本控制系统集成良好,在出现问题时支持回滚功能。通过明确的测试和监控步骤,该技能可确保更新后的 OpenRouter 集成在生产环境中继续按预期运行。

该技能主要面向使用 OpenRouter 的开发人员和团队,非常适合负责管理 SDK 更新或面临新版本破坏性变更的人员。 对于负责维护生产系统的 DevOps 工程师而言,该技能同样大有裨益,因为它使他们能够在跟踪变更的同时,安全地升级依赖项和配置。在更新或迁移 OpenRouter SDK 版本时,该工具有助于确保系统稳定性并最大限度地减少停机时间。

常见问题

如何触发openrouter-upgrade-migration 技能?

您可以使用“openrouter upgrade”、“openrouter migration”、“update openrouter”或“openrouter breaking changes”等短语来触发此技能。

使用此技能有哪些先决条件?

使用前提包括已部署 OpenRouter 集成,并已建立版本控制机制以确保回滚能力。

该技能是否兼容所有版本的 OpenRouter SDK?

该技能旨在用于升级和迁移 OpenRouter SDK 版本,但在操作前务必验证其与您具体 SDK 版本的兼容性。

如果迁移失败,我该怎么办?

如果迁移失败,请参阅位于 '{baseDir}/references/errors.md' 中的错误处理文档,以诊断并解决问题。

在 GitHub 上查看

OpenRouter Upgrade & Migration

Current State

!npm list openai 2>/dev/null | head -5!pip show openai 2>/dev/null | head -5

Overview

Migrating to OpenRouter from a direct provider API (OpenAI, Anthropic) is minimal: change base_url and api_key, add two headers. The OpenAI SDK works natively with OpenRouter. This skill covers migrating from direct APIs, switching between models, upgrading SDK versions, and running comparison tests.

Migration from Direct OpenAI

# BEFORE: Direct OpenAIfrom openai import OpenAIclient = OpenAI(api_key=os.environ["OPENAI_API_KEY"])response = client.chat.completions.create(    model="gpt-4o",    messages=[{"role": "user", "content": "Hello"}],    max_tokens=200,)# AFTER: Via OpenRouter (3 lines changed)from openai import OpenAIclient = OpenAI(    base_url="https://openrouter.ai/api/v1",     # ← Changed    api_key=os.environ["OPENROUTER_API_KEY"],     # ← Changed    default_headers={                              # ← Added        "HTTP-Referer": "https://my-app.com",        "X-Title": "my-app",    },)response = client.chat.completions.create(    model="openai/gpt-4o",  # ← Add provider prefix    messages=[{"role": "user", "content": "Hello"}],    max_tokens=200,)

Migration from Direct Anthropic

# BEFORE: Direct Anthropic SDKimport anthropicclient = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])response = client.messages.create(    model="claude-3-5-sonnet-20241022",    max_tokens=200,    messages=[{"role": "user", "content": "Hello"}],)content = response.content[0].text# AFTER: Via OpenRouter (using OpenAI SDK instead of Anthropic SDK)from openai import OpenAIclient = OpenAI(    base_url="https://openrouter.ai/api/v1",    api_key=os.environ["OPENROUTER_API_KEY"],    default_headers={        "HTTP-Referer": "https://my-app.com",        "X-Title": "my-app",    },)response = client.chat.completions.create(    model="anthropic/claude-3.5-sonnet",  # OpenRouter model ID    messages=[{"role": "user", "content": "Hello"}],    max_tokens=200,)content = response.choices[0].message.content  # OpenAI response format

TypeScript Migration

// BEFORE: Direct OpenAIimport OpenAI from "openai";const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });// AFTER: Via OpenRouterconst client = new OpenAI({  baseURL: "https://openrouter.ai/api/v1",  apiKey: process.env.OPENROUTER_API_KEY,  defaultHeaders: {    "HTTP-Referer": "https://my-app.com",    "X-Title": "my-app",  },});// Change model from "gpt-4o" to "openai/gpt-4o"

Migration Checklist

MIGRATION_CHECKLIST = {    "config": [        "base_url changed to https://openrouter.ai/api/v1",        "API key changed to OPENROUTER_API_KEY (sk-or-v1-...)",        "HTTP-Referer and X-Title headers added",        "Model IDs prefixed with provider/ (e.g., openai/gpt-4o)",    ],    "code": [        "All client initialization updated",        "Model IDs updated in all routes/configs",        "Error handling covers OpenRouter-specific codes (402, 408)",        "Streaming still works with new endpoint",        "Tool/function calling still works",    ],    "testing": [        "Same prompts produce comparable quality output",        "Latency within acceptable range (expect +50-100ms)",        "Token counts match expectations",        "Cost tracking updated for OpenRouter pricing",        "Fallback chain tested",    ],    "operations": [        "Credit balance sufficient for expected usage",        "Per-key credit limits configured",        "Monitoring updated to track OpenRouter metrics",        "Alerting on new error codes (402, 408)",        "Rollback plan documented",    ],}

Model ID Migration Map

Direct ProviderOpenRouter ID
gpt-4oopenai/gpt-4o
gpt-4o-miniopenai/gpt-4o-mini
o1openai/o1
claude-3-5-sonnet-20241022anthropic/claude-3.5-sonnet
claude-3-haiku-20240307anthropic/claude-3-haiku
gemini-2.0-flashgoogle/gemini-2.0-flash-001
llama-3.1-8b-instructmeta-llama/llama-3.1-8b-instruct

Comparison Test Script

def compare_migration(prompt: str, old_model: str, new_model: str):    """Run same prompt through old and new configurations to compare."""    import time    # New: OpenRouter    or_client = OpenAI(        base_url="https://openrouter.ai/api/v1",        api_key=os.environ["OPENROUTER_API_KEY"],        default_headers={"HTTP-Referer": "https://my-app.com", "X-Title": "migration-test"},    )    start = time.monotonic()    or_response = or_client.chat.completions.create(        model=new_model,        messages=[{"role": "user", "content": prompt}],        max_tokens=200, temperature=0,    )    or_latency = (time.monotonic() - start) * 1000    return {        "openrouter": {            "model": or_response.model,            "content": or_response.choices[0].message.content[:100],            "tokens": or_response.usage.prompt_tokens + or_response.usage.completion_tokens,            "latency_ms": round(or_latency),        },    }# Testresult = compare_migration(    "What is 2+2?",    old_model="gpt-4o",    new_model="openai/gpt-4o",)print(json.dumps(result, indent=2))

Feature Flag Migration

import osUSE_OPENROUTER = os.environ.get("USE_OPENROUTER", "false").lower() == "true"def get_llm_client():    """Feature flag for gradual migration."""    if USE_OPENROUTER:        return OpenAI(            base_url="https://openrouter.ai/api/v1",            api_key=os.environ["OPENROUTER_API_KEY"],            default_headers={"HTTP-Referer": "https://my-app.com", "X-Title": "my-app"},        )    else:        return OpenAI(api_key=os.environ["OPENAI_API_KEY"])def get_model_id(model: str) -> str:    """Map model IDs based on current backend."""    if USE_OPENROUTER and "/" not in model:        MODEL_MAP = {"gpt-4o": "openai/gpt-4o", "gpt-4o-mini": "openai/gpt-4o-mini"}        return MODEL_MAP.get(model, f"openai/{model}")    return model

Error Handling

ErrorCauseFix
401 after migrationUsing old API key with new base_urlUpdate to OpenRouter API key (sk-or-v1-...)
model_not_foundMissing provider prefixAdd openai/ or anthropic/ prefix to model ID
Different response formatSwitched from Anthropic SDK to OpenAI SDKUpdate response parsing: .choices[0].message.content
Higher latencyOpenRouter proxy overheadExpected: +50-100ms; use streaming to mask it

Enterprise Considerations

  • Migration from direct provider to OpenRouter requires only 3 lines of code change
  • Use feature flags for gradual migration (10% -> 50% -> 100%)
  • Run comparison tests on critical prompts before full migration
  • OpenRouter adds ~50-100ms overhead; use streaming to mask perceived latency
  • Keep direct provider keys active during migration for quick rollback
  • Update monitoring dashboards for OpenRouter-specific metrics (generation_id, provider used)

References

  • Examples | Errors
  • Quickstart | OpenAI Compatibility

所有文件

1 个文件

安装 openrouter-upgrade-migration

下载技能文件并将其解压到 .claude/skills/ 目录中。

下载ZIP

克隆仓库并复制技能文件到您的项目中。

git clone https://github.com/jeremylongshore/claude-code-plugins-plus-skills/blob/main/plugins/saas-packs/openrouter-pack/skills/openrouter-upgrade-migration/SKILL.md # Copy SKILL.md to your .claude/skills/ directory

复制 复制
快速设置: 将技能文件夹复制到 .claude/skills/ 目录下,Claude 会自动检测并使用该技能

相关技能

Verification & Quality Assurance
更新时间 2026-06-29
klingai-upgrade-migration
更新时间 2026-07-03
base44-cli
更新时间 2026-06-29
Railway CLI Management
更新时间 2026-07-02
OR