@agenttrace/proxy

中文文档
0.1.0发布于 2026/02/06Apache-2.0TypeScriptCommonJS近 30 天下载 3948

AgentTrace proxy server for buffering and forwarding agent events

原始使用文档
文档目录12 节
  1. Supported providers
  2. How it works
  3. Usage
  4. As part of the CLI (typical)
  5. Standalone CLI
  6. Programmatic
  7. Provider detection
  8. API key injection
  9. Rate limiting
  10. Health check
  11. Options
  12. License

@agenttrace/proxy

Transparent HTTP proxy for LLM API calls. Forwards requests to upstream providers, extracts usage metrics from responses (including SSE streams), and buffers them for delivery to an AgentTrace server.

Supported providers

  • OpenAI (api.openai.com)
  • Anthropic (api.anthropic.com)
  • Google (generativelanguage.googleapis.com)
  • Mistral (api.mistral.ai)
  • Cohere (api.cohere.com)
  • DeepSeek (api.deepseek.com)
  • Moonshot (api.moonshot.cn)
  • Zhipu / GLM (open.bigmodel.cn)
  • MiniMax (api.minimax.chat)
  • Baichuan (api.baichuan-ai.com)
  • Yi / 01.AI (api.lingyiwanwu.com)

How it works

  1. Your LLM client sends requests to the proxy instead of the provider directly
  2. The proxy detects the provider from the Host header or request path
  3. If configured, a provider API key is injected into the request headers
  4. If configured, a per-provider rate limit is enforced (429 on excess)
  5. The request is forwarded to the real upstream API
  6. The response is streamed back to your client in real-time
  7. Token counts, model, latency, and cost are extracted and buffered
  8. Buffered events are flushed to the AgentTrace server periodically

Both standard JSON responses and SSE streaming responses are supported.

Usage

As part of the CLI (typical)

npx agenttrace start
# Proxy starts on port 4000

Standalone CLI

agenttrace-proxy --api-key <token> --agent-id proxy \
  --provider-keys '{"openai":"sk-..."}' \
  --rate-limits '{"openai":{"maxRequests":100,"windowSeconds":60}}'

Programmatic

import { startProxy } from "@agenttrace/proxy";

const { server, shutdown } = startProxy({
  port: 4000,
  apiKey: "your-token",
  agentId: "proxy",
  endpoint: "http://localhost:8080/api/events",
  providerKeys: {
    openai: "sk-...",
    anthropic: "sk-ant-...",
  },
  rateLimits: {
    openai: { maxRequests: 100, windowSeconds: 60 },
  },
});

// Later
await shutdown();

Provider detection

The proxy auto-detects the target provider from the Host header. Set your LLM client's base URL to http://localhost:4000 and the proxy handles routing.

If auto-detection fails, set the x-target-url header to specify the upstream base URL explicitly.

API key injection

When providerKeys is configured, the proxy injects the correct auth header per provider:

ProviderHeader
OpenAI, Mistral, Cohere, DeepSeek, Moonshot, Zhipu, MiniMax, Baichuan, YiAuthorization: Bearer <key>
Anthropicx-api-key: <key>
Googlex-goog-api-key: <key>

If the client already provides the auth header, the proxy does not override it.

Rate limiting

When rateLimits is configured, the proxy enforces a sliding-window rate limit per provider. Requests exceeding the limit receive a 429 response with a Retry-After header.

Health check

GET http://localhost:4000/health

Options

OptionTypeDefaultDescription
portnumber4000Proxy listen port
apiKeystringrequiredAuth token for the AgentTrace server
agentIdstringrequiredAgent ID for recorded events
endpointstring—Event ingestion URL
flushIntervalnumber5000Event buffer flush interval in ms
maxBufferSizenumber50Max buffered events before auto-flush
providerKeysRecord<string, string>—Provider API keys to inject
rateLimitsRecord<string, RateLimitConfig>—Per-provider rate limits

License

Apache-2.0

版本与发布记录

@agenttrace/proxy 共发布 1 个版本,首次发布于 2026/02/06;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.1.0latest2026/02/069 个月前

关于 @agenttrace/proxy 的常见问题

@agenttrace/proxy 是什么?

AgentTrace proxy server for buffering and forwarding agent events

如何安装 @agenttrace/proxy?

在项目目录运行 npm install @agenttrace/proxy,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 agenttrace-proxy,可以用 npx agenttrace-proxy 直接运行。

@agenttrace/proxy 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@agenttrace/proxy 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@agenttrace/proxy 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@agenttrace/proxy 可以商用吗?

@agenttrace/proxy 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@agenttrace/proxy 的下载量有多少?

根据 npm 官方下载统计,@agenttrace/proxy 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,948 次,日均约 132 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@agenttrace/proxy 还在维护吗?

最新版本 0.1.0 发布于 2026/02/06(9 个月前);至今共发布 1 个版本,其中过去 12 个月发布了 1 个;首次发布于 2026/02/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。