用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/yanacuti1121/Yana-AI --skill portkey命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | portkey |
| description | Portkey AI gateway — unified LLM API, load balancing, fallbacks, caching, guardrails, observability |
| triggers | ["portkey","portkey gateway","llm gateway portkey","portkey fallback","portkey load balance","portkey cache","portkey guardrails","unified llm api","portkey virtual key","portkey config"] |
| do_not_use_for | ["single model calls without routing — use litellm directly","local model serving — use ollama","evaluation — use ragas/deepeval"] |
| see_also | ["litellm","langfuse","ollama-patterns"] |
from portkey_ai import Portkey
# Virtual keys abstract provider credentials
client = Portkey(
api_key="pk-...", # Portkey API key
virtual_key="anthropic-vk-...", # Virtual key for provider
)
# Drop-in OpenAI replacement
response = client.chat.completions.create(
model="claude-sonnet-4-6",
messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)
from portkey_ai import createHeaders, PORTKEY_GATEWAY_URL
import openai
# Config-based routing — define in Portkey dashboard or inline
config = {
"strategy": {
"mode": "fallback", # fallback | loadbalance | single
},
"targets": [
{
"virtual_key": "anthropic-vk",
"override_params": {"model": "claude-sonnet-4-6"},
"weight": 0.7,
},
{
"virtual_key": "openai-vk",
"override_params": {"model": "gpt-4o"},
"weight": 0.3,
},
],
}
# Use with openai client (Portkey as proxy)
openai_client = openai.OpenAI(
api_key="pk-...",
base_url=PORTKEY_GATEWAY_URL,
default_headers=createHeaders(
api_key="pk-...",
config=config,
),
)
lb_config = {
"strategy": {"mode": "loadbalance"},
"targets": [
{"virtual_key": "openai-vk-1", "weight": 50},
{"virtual_key": "openai-vk-2", "weight": 30},
{"virtual_key": "openai-vk-3", "weight": 20},
],
}
client = Portkey(api_key="pk-...", config=lb_config)
fallback_config = {
"strategy": {"mode": "fallback"},
"targets": [
{
"virtual_key": "primary-vk",
"override_params": {"model": "claude-opus-4-7"},
"retry": {"attempts": 2, "on_status_codes": [429, 500, 502, 503]},
},
{
"virtual_key": "backup-vk",
"override_params": {"model": "gpt-4o"},
},
],
}
client = Portkey(api_key="pk-...", config=fallback_config)
response = client.chat.completions.create(
model="claude-opus-4-7", # overridden by config
messages=[{"role": "user", "content": "Complex task"}],
)
cache_config = {
"cache": {
"mode": "semantic", # simple | semantic
"max_age": 3600, # seconds
},
"virtual_key": "openai-vk",
}
client = Portkey(api_key="pk-...", config=cache_config)
# Second identical (or semantically similar) call served from cache
r1 = client.chat.completions.create(model="gpt-4o", messages=[...])
r2 = client.chat.completions.create(model="gpt-4o", messages=[...])
print(r2.extensions.cache_status) # HIT
# Input/output guardrails — defined in Portkey dashboard
guardrail_config = {
"virtual_key": "anthropic-vk",
"guardrails": {
"input_guardrails": ["no-pii", "topic-restriction"],
"output_guardrails": ["no-harmful-content", "length-check"],
"on_fail": "block", # block | warn | replace
},
}
client = Portkey(api_key="pk-...", config=guardrail_config)
try:
response = client.chat.completions.create(
model="claude-sonnet-4-6",
messages=[{"role": "user", "content": user_input}],
)
except Exception as e:
# Guardrail blocked the request
print(f"Blocked: {e}")
client = Portkey(
api_key="pk-...",
virtual_key="anthropic-vk",
)
response = client.with_options(
metadata={
"user_id": "user-123",
"session_id": "sess-456",
"environment": "production",
"_prompt": "rag-v2", # prompt name for dashboard grouping
}
).chat.completions.create(
model="claude-sonnet-4-6",
messages=[{"role": "user", "content": query}],
)
# View traces at app.portkey.ai/logs
# Fetch and render prompts from Portkey dashboard
from portkey_ai import Portkey
client = Portkey(api_key="pk-...")
prompt = client.prompts.completions.create(
prompt_id="pp-my-prompt-id",
variables={"context": doc_context, "question": user_query},
)
print(prompt.choices[0].message.content)
config can be a dict (inline) or a string config ID from the dashboardstrategy.mode: "fallback" tries targets in order on error — not round-robinwith_options() returns a new client instance — does not mutate the original基于 SOC 职业分类