Skip to content

Developer guide

Agent framework setup guide

Connect OpenClaw, LangChain, AutoGen or Claude Code MCP to Tokonomix in minutes. This guide covers both gateway endpoints, per-framework config snippets and common error fixes.

Which endpoint to use

Two endpoints — pick the right one

Tokonomix exposes two gateway endpoints. Choosing the right one depends on whether your agent uses tool calls.

Mode B — Anthropic messages (tool-callers)

Use /api/anthropic/v1/messages when your agent sends or receives tool calls, needs streaming with tools, or uses prompt caching. This endpoint speaks the Anthropic Messages API directly — no translation layer. Consensus is not available on this endpoint.

OpenAI-compatible endpoint (consensus + plain chat)

Use /api/v1/chat/completions for single-model chat, or set model: "tokonomix-consensus" to run a multi-model council. Tool calls on this endpoint route to a single model (not the council). Streaming with tools is not enabled here.

When to use which

ScenarioEndpointModel param
Tool-calling agent (function/tool use)/api/anthropic/v1/messagesAny Anthropic model slug
Multi-model consensus / verification/api/v1/chat/completionstokonomix-consensus
Single-model chat (no tools)Either endpointAny model slug
Streaming response (no tool calls)Either endpointAny model slug

OpenClaw

OpenClaw connects to Tokonomix via the Anthropic base URL. Tool calling and streaming work out of the box.

# OpenClaw config (config.toml or .openclaw)
[api]
base_url = "https://tokonomix.ai/api/anthropic"
api_key  = "tok-your-key"

# For consensus (single-model passthrough via OpenAI endpoint):
# base_url = "https://tokonomix.ai/api/v1"
# model    = "tokonomix-consensus"

# Tool-calling agents: use the Anthropic base URL (Mode B).
# Consensus sessions: switch to the OpenAI-compat base URL above.

LangChain

Use the ChatOpenAI class with a custom base URL. For tool-calling agents, switch to the Anthropic messages endpoint.

# Python — plain chat or consensus
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="tokonomix-consensus",          # or any model slug
    base_url="https://tokonomix.ai/api/v1",
    api_key="tok-your-key",
)

# Tool-calling agents: switch to the Anthropic endpoint
from langchain_anthropic import ChatAnthropic

tool_llm = ChatAnthropic(
    model="claude-sonnet-4-6",
    base_url="https://tokonomix.ai/api/anthropic",
    api_key="tok-your-key",
)
# Bind tools as usual:
# agent_llm = tool_llm.bind_tools([my_tool])

AutoGen

AutoGen's OpenAIChatCompletionClient accepts a custom base URL. Set it to the Tokonomix OpenAI-compat endpoint for chat and consensus.

# Python — AutoGen 0.4+ (autogen-agentchat)
from autogen_ext.models.openai import OpenAIChatCompletionClient

# Plain chat or consensus
client = OpenAIChatCompletionClient(
    model="tokonomix-consensus",          # or any model slug
    base_url="https://tokonomix.ai/api/v1",
    api_key="tok-your-key",
)

# Tool-calling agents: use OpenAI client pointed at the OpenAI-compat endpoint.
# Consensus: pass model="tokonomix-consensus"; remove any tools= argument.
# Note: do NOT pass tools= when using tokonomix-consensus — that model does not
# accept tool definitions and will return a 400 error.

Claude Code MCP

Claude Code picks up Tokonomix via the MCP server. Once configured, Claude Code can call tokonomix_consensus_ask and tokonomix_single_ask directly.

// ~/.claude/settings.json  (or project .claude/settings.json)
{
  "mcpServers": {
    "tokonomix": {
      "command": "npx",
      "args": ["-y", "tokonomix-mcp"],
      "env": {
        "TOKONOMIX_API_KEY": "tok-your-key"
      }
    }
  }
}

// Available MCP tools after setup:
//   tokonomix_consensus_ask   — ask a question across multiple models at once
//   tokonomix_single_ask      — single-model call with full token accounting
//   tokonomix_get_balance     — check remaining token balance
//   tokonomix_list_models     — enumerate available models and capabilities
//
// Example usage in Claude Code:
//   tokonomix_consensus_ask({ prompt: "Review this function for edge cases", ... })
//
// Note: the MCP tools use the gateway internally — no separate endpoint config needed.

Common errors and fixes

Tool calls rejected on consensus

The tokonomix-consensus model does not accept tool definitions. Remove the tools array when using consensus. Use the Anthropic endpoint with a specific model for tool-calling agents.

400: need at least two providers for a council

Consensus requires two or more model providers to be enabled on your account. Check the model catalog (GET /api/v1/models) for available providers.

Embeddings call returns 404 or feature-flag error

Embeddings are behind a capability flag. Contact support to enable embeddings access, or use a direct provider endpoint in the meantime.

Raw JSON tool-call leak on OpenAI endpoint

If you see raw JSON tool-call output instead of a parsed response, your agent is using the OpenAI endpoint for tool calls. Switch to /api/anthropic/v1/messages (Mode B) — it correctly streams tool-call events.

401 Unauthorized

Pass your API key as Authorization: Bearer tok-your-key. The key must start with tok-. Keys are created under Account → API keys in your dashboard.