Connect

Connect

OpenAI SDKs, curl, agent frameworks, editor tools, the MCP server and the CLI.

View as Markdown

floprouter speaks the OpenAI chat completions API. Anything that lets you set an OpenAI-compatible base URL can use it. You need two values:

SettingValue
Base URLhttps://api.floprouter.com/v1
API keyyour fr_... key from the account page
Modelan id from /v1/models, for example qwen/qwen3-8b

Two things to know before you connect a tool:

  • Plain chat only. Tool calling is not supported, so a request that sends tools is rejected with 400. Agent modes in editors and frameworks usually send tools. Use their chat mode.
  • Replies are slow by API standards. 15 to 50 s on devnet. Raise client timeouts to at least 120 s.

OpenAI Python SDK

Python
from openai import OpenAI

client = OpenAI(base_url="https://api.floprouter.com/v1", api_key="fr_...", timeout=120)
reply = client.chat.completions.create(
    model="qwen/qwen3-8b",
    messages=[{"role": "user", "content": "Hello"}],
    extra_body={"flop": {"wait_for_settlement": False}},
)

Router fields (provider, flop) go in extra_body. The flop object of the response is in reply.model_extra["flop"].

OpenAI JavaScript SDK

JavaScript
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.floprouter.com/v1", apiKey: process.env.FLOPROUTER_API_KEY, timeout: 120_000 });
const reply = await client.chat.completions.create({
  model: "qwen/qwen3-8b",
  messages: [{ role: "user", content: "Hello" }],
  flop: { wait_for_settlement: false },
});

curl

Shell
curl https://api.floprouter.com/v1/chat/completions \
  -H "Authorization: Bearer $FLOPROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "qwen/qwen3-8b", "messages": [{"role": "user", "content": "Hello"}], "flop": {"wait_for_settlement": false}}'

Agent frameworks

Plain chat works; tool calls do not. The LangChain and Vercel AI SDK snippets below were checked against responses recorded from the live API, not with separate paid calls.

LangChain (Python, langchain-openai):

Python
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    base_url="https://api.floprouter.com/v1",
    api_key="fr_...",
    model="qwen/qwen3-8b",
    max_tokens=64,
    timeout=300,
    extra_body={"flop": {"wait_for_settlement": False}},
)
print(llm.invoke("What does a GPU miner do?").content)

Vercel AI SDK, with @ai-sdk/openai-compatible (it calls chat completions, which floprouter offers; the Responses API is not offered):

JavaScript
import { generateText, streamText } from "ai";
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";

const floprouter = createOpenAICompatible({
  name: "floprouter",
  baseURL: "https://api.floprouter.com/v1",
  apiKey: process.env.FLOPROUTER_API_KEY,
});

// fields under providerOptions.floprouter go into the request body
const { text } = await generateText({
  model: floprouter("qwen/qwen3-8b"),
  prompt: "In one sentence, what is a payment channel?",
  providerOptions: { floprouter: { flop: { wait_for_settlement: false } } },
});

An agent that needs tools can ask the model for a JSON action in plain text and parse it itself. That works today, because it is plain chat.

Editor tools and chat apps

Tools with an "OpenAI-compatible" provider setting take the base URL, key and model id above. Use chat, not agent or edit modes that rely on tool calls. Set the model's context and output limits low, since max_tokens sizes the escrow of every request.

MCP server

floprouter-mcp lets an agent list models and miners, run paid chat completions, and check sessions, balance and grant state. It never handles wallet keys.

Not published yet. The package is built and tested, but it is not on npm yet. The commands below work once it is published.

Shell
npx -y floprouter-mcp            # stdio, what desktop and IDE clients use
npx -y floprouter-mcp --http     # streamable HTTP on http://127.0.0.1:8792/mcp
VariableMeaning
FLOPROUTER_API_KEYYour fr_... key. Without it, only the read-only tools work. Falls back to the key saved by floprouter login.
FLOPROUTER_BASE_URLDefault https://api.floprouter.com
ToolWhat it doesPaid
list_modelsModels, ready and reachable miners, escrow per 1,000 tokensno
list_minersMiners with score, settle rate, sessions, strikes, calibration and reachability, with filtersno
get_minerOne miner in detailno
chatOne chat completion, auto or pinned miner. Returns the reply, session id, miner, escrow and payeryes
session_statusSettlement state of a sessionno
accountBalance, deposit address, fee and grant stateno
router_statusNetwork, sync state and payerno

Claude Code:

Shell
claude mcp add floprouter --scope user -e FLOPROUTER_API_KEY=fr_... -- npx -y floprouter-mcp

Claude Desktop (claude_desktop_config.json) and Cursor (~/.cursor/mcp.json):

JSON
{
  "mcpServers": {
    "floprouter": {
      "command": "npx",
      "args": ["-y", "floprouter-mcp"],
      "env": { "FLOPROUTER_API_KEY": "fr_..." }
    }
  }
}

Codex (~/.codex/config.toml):

TOML
[mcp_servers.floprouter]
command = "npx"
args = ["-y", "floprouter-mcp"]
env = { FLOPROUTER_API_KEY = "fr_..." }

chat returns once the reply is verified. Use session_status for the settlement; many MCP clients time a tool out before a settlement would finish.

CLI

floprouter browses miners and models, runs chat, and does the wallet steps on your own machine: creating a key, signing the grant, depositing FLOP. Keys stay local; the router only receives your address, a signature over its login challenge, and transactions you sign, which go to the chain.

Not published yet. Same as the MCP server: the commands below work once the package is on npm. Needs Node 18.17 or later.

Shell
npx floprouter models
npx floprouter miners --reachable --sort settle_rate
npx floprouter login --key-file ./my-wallet.json     # polkadot-js JSON export, or --seed-file, or a hidden prompt
npx floprouter grant                                 # one signature: your wallet stays the payer on chain
npx floprouter deposit 1                             # fund the balance for the router fee
npx floprouter chat "What is a payment channel?"
npx floprouter chat --miner <address> --stream "..."
npx floprouter session <id>

A seed or password is never accepted as a command-line argument. Before signing a grant, the CLI checks the chain's genesis hash against the router's, builds the call itself, and refuses anything other than flopSessionKeys.createSession limited to ComputeChannel.

For agents reading this