360 Secure SkillHub
360 安全技能中心

Tokenlab Openai Compatible Migration

面向需要把现有 OpenAI 兼容 SDK、OpenRouter/LiteLLM/LangChain 配置迁移到 TokenLab 的场景,给出最小改动方案:替换 base URL 与 API Key 环境变量、保留原生 Anthropic/Gemini 语义、补充模型发现、冒烟测试与回滚说明,避免重写架构或硬编码密钥。

hedging8563
hedging8563
热度 13.71
最近更新 2026-07-10 23:58:26
分类:开发依赖:第三方 API应用场景:API 集成 / 代码生成 / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add tokenlab-openai-compatible-migration
Metadata
name
tokenlab-openai-compatible-migration
description
Migrate OpenAI-compatible apps, SDKs, examples, and environment variables to TokenLab while preserving request semantics and adding live model discovery.
license
MIT
metadata
{"category":"coding"}

TokenLab OpenAI-Compatible Migration

Use this skill when a user wants to move an existing OpenAI-compatible integration, OpenRouter setup, LiteLLM config, LangChain/LlamaIndex app, or custom SDK wrapper to TokenLab.

What this skill should deliver

  • A minimal diff or config change that preserves the existing user path.
  • The correct TokenLab base URL and API key environment variable.
  • A model migration note with live discovery commands.
  • A native endpoint note when the old code actually needs Responses, Anthropic Messages, Gemini, media, audio, embeddings, rerank, or translation behavior.
  • A rollback note that restores the previous provider config.

Default migration rules

  • OpenAI-compatible SDKs:
    • base URL: https://api.tokenlab.sh/v1
    • auth: Authorization: Bearer $TOKENLAB_API_KEY
    • chat path: /v1/chat/completions
  • Anthropic-native clients:
    • base URL: https://api.tokenlab.sh
    • messages path: /v1/messages
  • Gemini-native clients:
    • base URL: https://api.tokenlab.sh
    • generateContent path: /v1beta/models/{model}:generateContent
  • Live discovery:
    • GET https://api.tokenlab.sh/v1/models
    • GET https://api.tokenlab.sh/v1/models?recommended_for=<scene>
    • GET https://api.tokenlab.sh/v1/models/:model

Preferred approach

  1. Locate the current provider config, environment variables, and model IDs.
  2. Make the smallest possible change first:
    • replace base URL
    • replace API key variable
    • keep SDK/client shape intact
  3. Add model discovery only where the app currently hardcodes provider-specific models.
  4. Keep native semantics when the source integration uses Responses, Anthropic Messages, Gemini content parts, tools, media, audio, embeddings, rerank, or translation.
  5. Provide a smoke test command for the migrated path.

Output format

  • One short explanation of the migration surface.
  • A focused diff, config block, or runnable replacement snippet.
  • One smoke test command.
  • One model discovery command.
  • One rollback line naming the previous base URL/env vars.

Avoid

  • Do not rewrite the user's SDK architecture if a base URL change is enough.
  • Do not flatten native Anthropic or Gemini payloads into generic chat unless the user explicitly accepts that behavior change.
  • Do not silently change models when the user's existing model has no obvious TokenLab equivalent.
  • Do not embed API keys in source files or prompts.
  • Do not claim feature parity without checking the model details endpoint.

Edge Cases

  • If an app has separate base URLs for chat, embeddings, and media, migrate one family at a time.
  • If the existing app uses OpenRouter model slugs, map to TokenLab public model IDs only after catalog lookup.
  • If the user's previous provider had provider-specific headers, keep only headers that TokenLab documents or that the user's app still needs.