跳到主内容
@wquguru
精选75MarkTechPost(RSS)产品发布/更新

NVIDIA发布Switchyard:用于LLM流量路由与格式转换的Rust代理

Meet Switchyard: A Rust Proxy and Library That Routes and Translates LLM Traffic Across OpenAI and Anthropic APIs

原文
发到 X

Teams running coding agents hit the same wall. Claude Code speaks the Anthropic Messages API, Codex CLI speaks OpenAI, and the model a team actually wants to serve sits behind vLLM, NVIDIA NIM, or Ollama. Rewriting the agent is not an option, so the translation layer has to live somewhere else.

运行编码代理的团队遇到了同样的瓶颈。Claude Code 使用 Anthropic Messages API,Codex CLI 使用 OpenAI,而团队真正希望部署的模型则位于 vLLM、NVIDIA NIM 或 Ollama 之后。重写代理并非可行方案,因此翻译层必须存在于其他地方。

Switchyard is NVIDIA’s answer: a Rust proxy and library for LLM traffic that routes requests across providers, translates between OpenAI and Anthropic formats, records operational metrics, and exposes typed, composable routing algorithms. It is released under Apache 2.0 with documentation at docs.nvidia.com/nemo/switchyard.

Switchyard 是 NVIDIA 给出的答案:一个用于 LLM 流量的 Rust 代理和库,可在不同提供商之间路由请求,在 OpenAI 和 Anthropic 格式之间进行转换,记录操作指标,并暴露类型化、可组合的路由算法。它采用 Apache 2.0 许可证发布,文档位于 docs.nvidia.com/nemo/switchyard。

Is it deployable? Yes, but for evaluation only. The binary installs from crates.io and the launcher from PyPI, and it self-hosts anywhere, but NVIDIA labels Switchyard pre-alpha and experimental, warns it is not for production use, and expects the API and algorithms to change significantly before v1.0.

它可以部署吗?可以,但仅限评估用途。二进制文件从 crates.io 安装,启动器从 PyPI 安装,并且可以在任何地方自托管,但 NVIDIA 将 Switchyard 标记为预 Alpha 版和实验性版本,警告其不应用于生产环境,并预计 API 和算法在 v1.0 之前会发生重大变化。

What Switchyard does

Switchyard 的功能

Clients keep their native API. Switchyard decodes the inbound request into provider-neutral Rust types, runs a routing algorithm to pick a backend, re-encodes the request in that backend’s own wire format, calls it, and translates the response, including streaming events, back into the shape the client expects.

客户端保留其原生 API。Switchyard 将入站请求解码为与提供商无关的 Rust 类型,运行路由算法以选择后端,以该后端的专用传输格式重新编码请求,调用它,并将响应(包括流式事件)转换回客户端期望的形状。

The server accepts three inbound formats: OpenAI Chat Completions, OpenAI Responses, and Anthropic Messages. Any of the three can address any route, and each configured LLM client selects one upstream format of its own. That decoupling is the point: the agent’s API and the backend’s API no longer have to match.

服务器接受三种入站格式:OpenAI Chat Completions、OpenAI Responses 和 Anthropic Messages。这三种中的任何一种都可以寻址任何路由,每个配置的 LLM 客户端选择其自身的上游格式之一。这种解耦正是其核心目的:代理的 API 和后端的 API 不再需要匹配。

Three ways to run it

三种运行方式

The launcher path targets coding agents. Install the published tool with uv tool install --python 3.12 "nemo-switchyard[cli]", then run switchyard launch claude, switchyard launch codex, or switchyard launch openclaw against a packaged deployment or your own TOML file.

启动器路径针对编码代理。使用 uv tool install --python 3.12 "nemo-switchyard[cli]" 安装发布的工具,然后针对打包好的部署或您自己的 TOML 文件运行 switchyard launch claude、switchyard launch codex 或 switchyard launch openclaw。

The server path installs the standalone proxy with cargo install --locked switchyard-server, validates a config with --dry-run, and serves on a host and port you choose.

服务器路径通过 cargo install --locked switchyard-server 安装独立代理,使用 --dry-run 验证配置,并在您选择的主机和端口上提供服务。

The library path uses switchyard-libsy, which embeds the routing algorithms in a Rust application without owning an HTTP stack. It never calls a model itself; the algorithm decides which target to use and hands every model call back to the caller.

库路径使用 switchyard-libsy,它将路由算法嵌入到 Rust 应用程序中,而不拥有 HTTP 栈。它本身从不调用模型;算法决定使用哪个目标,并将每个模型调用交还给调用者。

Routing algorithms

路由算法

A route is one client-visible model ID plus the algorithm behind it. The server supports:

路由是一个客户端可见的模型 ID 及其背后的算法。服务器支持:

  • passthrough sends every request to one target.
  • random splits traffic across targets using optional relative weights, with an optional seed that reproduces the selection sequence. This is the A/B and cost-experiment path.
  • llm_classifier calls a classifier target for a capability verdict, then routes to a weak or strong target. base_threshold is required; min_confidence, capability_elevated_floor, and session_affinity tune it, and anything the judge cannot decide falls through to the strong target. Setting mode = "escalation" runs every turn on the weak tier first and lets a judge decide whether to rerun it on the strong tier.
  • stage_router scores tool-result and agent-progress signals from recent turns to pick a capable or efficient target, avoiding an extra classifier call on most turns.
  • passthrough 将每个请求发送到单一目标。
  • 在目标之间随机分配流量,使用可选的相对权重,并支持可选的种子以复现选择序列。这是 A/B 测试和成本实验的路径。
  • llm_classifier 调用分类器目标以获取能力判定结果,然后路由到弱模型或强模型目标。base_threshold 为必填项;min_confidence、capability_elevated_floor 和 session_affinity 用于调整该阈值,而法官无法决定的任何情况都会回退到强模型目标。设置 mode = "escalation" 会在每一轮先运行弱模型层,并由法官决定是否在强模型层重新运行。
  • stage_router 对最近几轮的 tool-result 和 agent-progress 信号进行评分,以选择一个有能力的或高效的模型目标,从而避免在大多数轮次中额外调用分类器。

Strong, weak, capable, and efficient are roles inside a route, not fixed properties of a model. The same upstream model can serve different roles in different routes.

Strong(强)、weak(弱)、capable(有能力)和 efficient(高效)是路由内部的角色,而非模型的固定属性。同一个上游模型可以在不同的路由中担任不同的角色。

Observability

可观测性

GET /metrics returns Prometheus text from the server’s process-wide OpenTelemetry provider. The families cover requests, errors, model-call latency, full-turn latency, prompt, completion, cached, cache-creation, and reasoning tokens, and upstream HTTP attempts by outcome and code. A tier label carries strong or weak for distinguishable classifier decisions, and classifier calls are excluded from those families.

GET /metrics 返回来自服务器进程级 OpenTelemetry 提供者的 Prometheus 文本格式指标。这些指标涵盖请求、错误、模型调用延迟、完整轮次延迟、提示词、补全、缓存命中、缓存创建以及推理 token,并按结果和状态码统计上游 HTTP 尝试次数。tier 标签携带 strong 或 weak 以区分可辨识的分类器决策,且分类器调用不计入这些指标家族。

The more interesting metric is switchyard_routing_overhead_ms, which reports the algorithm’s run time minus the call that served the request. Classifier calls are not subtracted, so an LLM-classifier route reports its classification time here while passthrough and random report the sub-millisecond cost of picking a target. Buckets start at 0.1 ms. Separately, --routing-log-file appends a JSON record per completed response, and GET /v1/routing/session-stats returns per-session call and token totals from that log.

更有趣的指标是 switchyard_routing_overhead_ms,它报告算法的运行时间减去服务请求的那次调用时间。分类器调用未被扣除,因此 LLM-classifier 路由会在此处报告其分类时间,而 passthrough 和 random 则报告选择目标所需的亚毫秒级开销。桶起始值为 0.1 ms。此外,--routing-log-file 会为每个完成的响应追加一条 JSON 记录,GET /v1/routing/session-stats 则从该日志中返回按会话统计的调用次数和 token 总量。

Configuration

配置

A TOML deployment has three layers: llm_clients define base URL, wire format, credential environment variable, and retry policy; targets bind one upstream model ID to a client; routes expose one client-visible model ID and its algorithm. Secrets never sit in the file, since api_key_env only names an environment variable. max_retries defaults to 2 and applies to transport failures, timeouts, HTTP 408/429, and 5xx responses.

TOML 部署包含三个层次:llm_clients 定义基础 URL、传输格式、凭据环境变量和重试策略;targets 将一个上游模型 ID 绑定到一个客户端;routes 暴露一个客户端可见的模型 ID 及其算法。密钥从不直接存储在文件中,因为 api_key_env 仅指定一个环境变量名。max_retries 默认为 2,适用于传输失败、超时、HTTP 408/429 以及 5xx 响应。

Key Takeaways

关键要点

  • Switchyard is an Apache-2.0 Rust proxy and library that routes and translates LLM traffic.
  • It bridges OpenAI Chat, OpenAI Responses, and Anthropic Messages in both directions, including streams.
  • Four route types ship: passthrough, random, LLM-classifier, and signal-driven stage router.
  • Prometheus metrics isolate routing overhead from model-call latency, per model and tier.
  • It is pre-alpha and explicitly not for production, so treat it as an evaluation tool.
  • Switchyard 是一个基于 Apache-2.0 许可的 Rust 代理和库,用于路由和转换 LLM 流量。
  • 它在 OpenAI Chat、OpenAI Responses 和 Anthropic Messages 之间双向桥接,包括流式传输。
  • 提供四种路由类型:直通(passthrough)、随机(random)、LLM 分类器(LLM-classifier)以及信号驱动的阶段路由器(signal-driven stage router)。
  • Prometheus 指标将每个模型和层级的路由开销与模型调用延迟隔离开来。
  • 它处于预 Alpha 阶段,明确不用于生产环境,因此请将其视为评估工具。

Check out the GitHub Repo and Documentation. Also, feel free to follow us on Twitter and don’t forget to join our 150k+ML SubReddit and Subscribe to our Newsletter. Wait! are you on telegram? now you can join us on telegram as well.

查看 GitHub 仓库和文档。此外,欢迎在 Twitter 上关注我们,别忘了加入我们拥有 150k+ 成员的 ML SubReddit 并订阅我们的新闻通讯。等等!你在 Telegram 上吗?现在你也可以加入我们的 Telegram 群组。

Need to partner with us for promoting your GitHub Repo OR Hugging Face Page OR Product Release OR Webinar etc.? Connect with us

需要与我们合作推广你的 GitHub 仓库、Hugging Face 页面、产品发布或网络研讨会等?请联系我们

The post Meet Switchyard: A Rust Proxy and Library That Routes and Translates LLM Traffic Across OpenAI and Anthropic APIs appeared first on MarkTechPost.

本文《遇见 Switchyard:一个跨 OpenAI 和 Anthropic API 路由和翻译 LLM 流量的 Rust 代理和库》首发于 MarkTechPost。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

另一事件,读法相近