fx

Run fx agents on AnyRouter with the provider plugin. Install it, set one key, and pass anyrouter() to createFxAgent.

fx is an agent runtime from Vercel Labs (source). The AnyRouter provider plugin lets an fx agent run on any AnyRouter model with one key.

Set up

The plugin is not on npm. Install it from GitHub, with libfx (^0.0.16) as its peer dependency:

bash
npm install libfx github:AnyRouterHQ/fx-provider-anyrouter#v0.1.0

Set your key, from the dashboard:

bash
export ANYROUTER_API_KEY=sk-ar-v1-...

Pass anyrouter() as the provider:

ts
import { createFxAgent } from "libfx";
import { anyrouter, anyrouterCredentials } from "fx-provider-anyrouter";

const agent = createFxAgent({
  provider: anyrouter(),
  model: "anyrouter/hermes",
  credentials: anyrouterCredentials(),
});

for await (const event of agent.session().prompt("Hello")) {
  if (event.type === "text_delta") process.stdout.write(event.delta);
}

model must be an AnyRouter id. fx's default model will not work with a custom provider.

Newer models

anyrouter() ships with a snapshot of 88 models. To use the live catalog instead:

ts
import { fetchAnyRouterProvider } from "fx-provider-anyrouter";

const provider = await fetchAnyRouterProvider();

fetchAnyRouterModels() returns just the models record.

Without the plugin

fx accepts a plain custom provider:

ts
createFxAgent({
  provider: {
    name: "anyrouter",
    baseUrl: "https://anyrouter.dev/api/v1",
    models: { "anyrouter/hermes": { contextWindow: 1050000, maxOutputTokens: 64000, supportsToolUse: true } },
  },
  model: "anyrouter/hermes",
  credentials: async () => ({ apiKey: process.env.ANYROUTER_API_KEY! }),
});

Troubleshooting

SymptomFix
401Check that ANYROUTER_API_KEY is set in the process that runs the turn, and that the key is valid.
Unknown model idUse the owner/model form from the models page, for example anyrouter/hermes.
A new model is missing from the bundled listUse fetchAnyRouterProvider() or fetchAnyRouterModels().

AnyRouter routes requests to third-party models. Models and outputs are provided as is, with no warranty; you use them at your own risk. Disclaimer