Entwicklerhandbuch
Agent-Framework-Setup-Anleitung
Verbinden Sie OpenClaw, LangChain, AutoGen oder Claude Code MCP in Minuten mit Tokonomix. Diese Anleitung erklärt beide Gateway-Endpunkte, Framework-Konfigurations-Snippets und häufige Fehlerbehebungen.
Welchen Endpunkt verwenden?
Zwei Endpunkte — den richtigen wählen
Tokonomix bietet zwei Gateway-Endpunkte. Die Wahl hängt davon ab, ob Ihr Agent Tool-Calls verwendet.
Verwenden Sie /api/anthropic/v1/messages, wenn Ihr Agent Tool-Calls sendet oder empfängt, Streaming mit Tools benötigt oder Prompt-Caching nutzt. Dieser Endpunkt spricht die Anthropic Messages API direkt an — ohne Übersetzungsschicht. Konsens ist auf diesem Endpunkt nicht verfügbar.
Verwenden Sie /api/v1/chat/completions für Chat mit einem Modell, oder setzen Sie model: "tokonomix-consensus", um einen Multi-Modell-Council zu starten. Tool-Calls auf diesem Endpunkt werden an ein einzelnes Modell weitergeleitet (nicht an den Council). Streaming mit Tools ist hier nicht verfügbar.
Wann welchen Endpunkt verwenden
| Szenario | Endpunkt | Modell-Parameter |
|---|---|---|
| Agent mit Tool-Calls (Function/Tool Use) | /api/anthropic/v1/messages | Beliebiger Anthropic-Modell-Slug |
| Multi-Modell-Konsens / Verifikation | /api/v1/chat/completions | tokonomix-consensus |
| Einfacher Chat mit einem Modell (keine Tools) | Beide Endpunkte | Beliebiger Modell-Slug |
| Streaming-Antwort (keine Tool-Calls) | Beide Endpunkte | Beliebiger Modell-Slug |
OpenClaw
OpenClaw verbindet sich über die Anthropic-Basis-URL mit Tokonomix. Tool-Calling und Streaming funktionieren sofort.
# 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
Verwenden Sie die ChatOpenAI-Klasse mit einer benutzerdefinierten Basis-URL. Für Tool-Calling-Agents wechseln Sie zum Anthropic-Messages-Endpunkt.
# 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 akzeptiert eine benutzerdefinierte Basis-URL. Setzen Sie diese auf den OpenAI-kompatiblen Tokonomix-Endpunkt für Chat und Konsens.
# 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 liest Tokonomix über den MCP-Server. Nach der Konfiguration kann Claude Code tokonomix_consensus_ask und tokonomix_single_ask direkt aufrufen.
// ~/.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.Häufige Fehler und Lösungen
Das Modell tokonomix-consensus akzeptiert keine Tool-Definitionen. Entfernen Sie das tools-Array bei Verwendung von Konsens. Verwenden Sie den Anthropic-Endpunkt mit einem bestimmten Modell für Tool-Calling-Agents.
Konsens erfordert, dass zwei oder mehr Modell-Provider auf Ihrem Konto aktiviert sind. Prüfen Sie den Modellkatalog (GET /api/v1/models) auf verfügbare Provider.
Embeddings befinden sich hinter einem Capability-Flag. Kontaktieren Sie den Support, um Embeddings freizuschalten, oder verwenden Sie in der Zwischenzeit einen direkten Provider-Endpunkt.
Wenn Sie rohes JSON Tool-Call-Output statt einer verarbeiteten Antwort sehen, verwendet Ihr Agent den OpenAI-Endpunkt für Tool-Calls. Wechseln Sie zu /api/anthropic/v1/messages (Mode B) — dieser streamt Tool-Call-Events korrekt.
Übergeben Sie Ihren API-Schlüssel als Authorization: Bearer tok-your-key. Der Schlüssel muss mit tok- beginnen. Schlüssel werden unter Konto → API-Schlüssel im Dashboard erstellt.