Naar inhoud

Ontwikkelaarsgids

Installatiegids voor agent-frameworks

Verbind OpenClaw, LangChain, AutoGen of Claude Code MCP in enkele minuten met Tokonomix. Deze gids behandelt beide gateway-endpoints, configuratiesnippets per framework en veelvoorkomende foutoplossingen.

Welk endpoint gebruik je?

Twee endpoints — kies het juiste

Tokonomix biedt twee gateway-endpoints. Welk endpoint je kiest, hangt af van of je agent tool-calls gebruikt.

Mode B — Anthropic messages (tool-callers)

Gebruik /api/anthropic/v1/messages als je agent tool-calls verstuurt of ontvangt, streaming met tools nodig heeft, of prompt-caching gebruikt. Dit endpoint spreekt de Anthropic Messages API direct aan — zonder vertaallaag. Consensus is niet beschikbaar op dit endpoint.

OpenAI-compatibel endpoint (consensus & gewone chat)

Gebruik /api/v1/chat/completions voor chat met één model, of zet model: "tokonomix-consensus" om een multi-model council te starten. Tool-calls op dit endpoint worden doorgestuurd naar één model (niet de council). Streaming met tools is hier niet beschikbaar.

Wanneer welk endpoint gebruiken

ScenarioEndpointModel-parameter
Agent met tool-calls (function/tool use)/api/anthropic/v1/messagesElk Anthropic-model-slug
Multi-model consensus / verificatie/api/v1/chat/completionstokonomix-consensus
Gewone chat met één model (geen tools)Beide endpointsElk model-slug
Streaming-respons (geen tool-calls)Beide endpointsElk model-slug

OpenClaw

OpenClaw verbindt via de Anthropic base URL met Tokonomix. Tool-calling en streaming werken direct.

# 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

Gebruik de ChatOpenAI-klasse met een aangepaste base URL. Schakel voor tool-calling agents over naar het 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

AutoGens OpenAIChatCompletionClient accepteert een aangepaste base URL. Stel die in op het Tokonomix OpenAI-compatibele endpoint voor chat en 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 leest Tokonomix via de MCP-server. Na configuratie kan Claude Code direct tokonomix_consensus_ask en tokonomix_single_ask aanroepen.

// ~/.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.

Veelvoorkomende fouten en oplossingen

Tool-calls afgewezen bij consensus

Het tokonomix-consensus-model accepteert geen tool-definities. Verwijder de tools-array bij gebruik van consensus. Gebruik het Anthropic-endpoint met een specifiek model voor tool-calling agents.

400: minimaal twee providers nodig voor een council

Consensus vereist dat er twee of meer model-providers zijn ingeschakeld op je account. Controleer de modelcatalogus (GET /api/v1/models) voor beschikbare providers.

Embeddings-call geeft 404 of feature-flag-fout

Embeddings zitten achter een capability-flag. Neem contact op met support om embeddings in te schakelen, of gebruik in de tussentijd een directe provider-endpoint.

Rauwe JSON tool-call-output op het OpenAI-endpoint

Als je ruwe JSON tool-call-output ziet in plaats van een verwerkt antwoord, gebruikt je agent het OpenAI-endpoint voor tool-calls. Schakel over naar /api/anthropic/v1/messages (Mode B) — dat streamt tool-call-events correct.

401 Unauthorized

Stuur je API-sleutel mee als Authorization: Bearer tok-your-key. De sleutel moet beginnen met tok-. Sleutels maak je aan via Account → API keys in je dashboard.