portkey-typescript-sdk

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Portkey TypeScript SDK

Portkey TypeScript SDK

<!-- PLACEHOLDER: Replace this content with your actual SKILL.md content. This file should contain comprehensive instructions for AI agents on how to: - Install and configure the Portkey TypeScript SDK - Use core features (completions, chat, embeddings) - Implement observability and tracing - Set up caching, fallbacks, and load balancing - Handle errors properly - Work with different LLM providers through Portkey Keep the file under 500 lines. Move detailed reference material to the references/ directory. -->
<!-- 占位符:将此内容替换为实际的SKILL.md内容。 本文件应包含AI代理所需的全面说明,包括: - 安装和配置Portkey TypeScript SDK - 使用核心功能(补全、对话、嵌入) - 实现可观测性和追踪 - 设置缓存、降级和负载均衡 - 正确处理错误 - 通过Portkey与不同的LLM提供商协作 请将文件控制在500行以内。详细参考资料请移至references/目录。 -->

When to use this skill

何时使用该技能

Use this skill when:
  • The user wants to integrate Portkey into a TypeScript or JavaScript application
  • The user needs LLM observability, caching, or reliability features
  • The user wants to route requests across multiple LLM providers
  • The user mentions "Portkey", "AI gateway", or "LLM observability" in Node.js/TS context
当以下情况时使用本技能:
  • 用户希望将Portkey集成到TypeScript或JavaScript应用中
  • 用户需要LLM可观测性、缓存或可靠性相关功能
  • 用户希望在多个LLM提供商之间路由请求
  • 用户在Node.js/TS场景中提到了“Portkey”、“AI gateway”或“LLM observability”

Installation

安装

bash
npm install portkey-ai
bash
npm install portkey-ai

or

or

yarn add portkey-ai
yarn add portkey-ai

or

or

pnpm add portkey-ai
undefined
pnpm add portkey-ai
undefined

Quick Start

快速开始

typescript
import Portkey from 'portkey-ai';

const client = new Portkey({
  apiKey: 'YOUR_PORTKEY_API_KEY',
  virtualKey: 'YOUR_VIRTUAL_KEY', // Optional: for provider routing
});

const response = await client.chat.completions.create({
  model: 'gpt-4',
  messages: [
    { role: 'user', content: 'Hello!' }
  ],
});

console.log(response.choices[0].message.content);
<!-- Add your complete SDK documentation below -->
typescript
import Portkey from 'portkey-ai';

const client = new Portkey({
  apiKey: 'YOUR_PORTKEY_API_KEY',
  virtualKey: 'YOUR_VIRTUAL_KEY', // Optional: for provider routing
});

const response = await client.chat.completions.create({
  model: 'gpt-4',
  messages: [
    { role: 'user', content: 'Hello!' }
  ],
});

console.log(response.choices[0].message.content);
<!-- 在下方添加完整的SDK文档 -->