XCoffee API Tutorials
Set up Codex, Claude Code, OpenClaw, Hermes, Pi and Cursor with copyable examples and connection checks.
Last updated: 2026-11-07
Choose your tool
Copy your customer key, protocol-specific Base URL and available group name from the API console, then choose a tutorial. Codex, Claude Code and OpenClaw steps are expanded by default, ready to read and copy.
Connect
- Obtain a pass and copy a customer key from the user center. Do not use an administrator key or a Magpie internal key.
- In the API console, select your client’s protocol and copy its Base URL and example.
- Set the model to an available group’s API name. The home page lists operator-published group members; names and membership can change.
Routing uses the requested group. Your client handles task splitting and choosing groups for subtasks. Magpie can try another member within its group before output begins, subject to the operator’s group settings. The website does not replay a generation after partial output or caller cancellation.
Choose your Agent
Start with an installed client, an active pass and a customer key. For coding, the examples use xcoffee-coding. If that group is absent from your API console, replace it with an available published API name.
| Client | Protocol | Base URL |
|---|---|---|
| Claude Code / Claude Code settings in CC Switch | Anthropic Messages | https://api.xcoff.ee |
| Codex CLI | OpenAI Responses | https://api.xcoff.ee/v1 |
| OpenClaw | OpenAI Chat Completions | https://api.xcoff.ee/v1 |
| Hermes / Pi | OpenAI Chat Completions | https://api.xcoff.ee/v1 |
| Cursor (custom endpoint required) | OpenAI Compatible | https://api.xcoff.ee/v1 |
| Other Agents supporting Chat Completions | OpenAI Compatible / Chat Completions | https://api.xcoff.ee/v1 |
Use a group API name, not a member model shown on the homepage. Examples: xcoffee-coding for coding and tools, xcoffee-fast for short tasks, and xcoffee for general tasks. The API console determines available groups, protocols and current multipliers. The service routes within your chosen group; individual member models cannot be selected.
Set your key locally
The terminal examples require the corresponding CLI to be installed and use Bash or Zsh on macOS/Linux. Run this in the same terminal where you will launch the Agent, paste your customer key at the prompt, and press Enter. Input is hidden:
printf 'XCoffee API Key: '
read -rs XCOFFEE_API_KEY
export XCOFFEE_API_KEY
printf '\n'
The variable lasts for this terminal and its child processes. Set it again after closing the terminal. Never put the key in a project, commit it or paste it into a chat. Use your client's credential settings for persistent storage. Desktop apps and other terminals do not automatically inherit this variable.
Windows PowerShell: enter your key
Run this in a fresh PowerShell window and paste your customer key when prompted:
$secret = Read-Host "XCoffee API Key" -AsSecureString
$env:XCOFFEE_API_KEY = [System.Net.NetworkCredential]::new("", $secret).Password
Remove-Variable secret
Check the address and key first
macOS / Linux:
curl --fail-with-body https://api.xcoff.ee/v1/models \
-H "Authorization: Bearer $XCOFFEE_API_KEY"
PowerShell:
Invoke-RestMethod -Uri "https://api.xcoff.ee/v1/models" `
-Headers @{ Authorization = "Bearer $env:XCOFFEE_API_KEY" }
A successful response contains a model list. This checks the address, authentication and visible group names; select the matching protocol and complete the conversation and tool checks below too.
Settings in other desktop clients
Add a custom provider using the matching address above, your customer key and an available group API name. Save and select that provider. Usually the key field takes the key alone, without a Bearer prefix. If the field explicitly asks for a full request URL, use https://api.xcoff.ee/v1/chat/completions for Chat Completions. Do not duplicate /v1.
Setup for your client
Open the tool you use. You do not need to read every tutorial.
Claude Code: connect to XCoffee
1. Install and check the version
If needed, follow the official Claude Code installation instructions, then run claude --version. This section covers the CLI. The desktop application and editor extensions have different configuration entry points.
2. macOS / Linux: launch from the same terminal
Set XCOFFEE_API_KEY using the instructions above. Select Anthropic Messages in the API console and confirm that xcoffee-coding is an available group. Replace the model value below if your group has another name.
env -u ANTHROPIC_API_KEY \
ANTHROPIC_BASE_URL=https://api.xcoff.ee \
ANTHROPIC_AUTH_TOKEN="$XCOFFEE_API_KEY" \
claude --model xcoffee-coding
Use the site origin as Base URL, without /v1/messages. ANTHROPIC_AUTH_TOKEN sends your customer key in a Bearer header. XCoffee also accepts x-api-key; choose one authentication method for the first setup.
3. Windows: use a fresh PowerShell window
First enter your key using the PowerShell instructions above, then run:
Remove-Item Env:ANTHROPIC_API_KEY -ErrorAction SilentlyContinue
$env:ANTHROPIC_BASE_URL = "https://api.xcoff.ee"
$env:ANTHROPIC_AUTH_TOKEN = $env:XCOFFEE_API_KEY
claude --model xcoffee-coding
These variables apply to this terminal and programs started from it. Send “Reply only: connection successful”, run /status to check the XCoffee Base URL, and confirm the request appears in your XCoffee API console.
4. Persistent settings and other launchers
For persistent use, merge the env settings into your own ~/.claude/settings.json (%USERPROFILE%\.claude\settings.json on Windows). Preserve unrelated settings and keep real keys out of version control. A matching settings-file env value can override a shell variable; check it if requests still use an old URL.
In CC Switch, configure a Claude Code custom provider with the XCoffee name, origin https://api.xcoff.ee, customer key and available group name. Choose Anthropic Messages when offered. For the VS Code extension, follow the official gateway instructions for claudeCode.environmentVariables; an editor started from the Dock or Start menu does not automatically inherit terminal exports.
If request history shows additional calls to unavailable sonnet, opus or haiku names, map the relevant aliases to the same available Messages group, or to separate groups that your account can use:
export ANTHROPIC_DEFAULT_SONNET_MODEL=xcoffee-coding
export ANTHROPIC_DEFAULT_OPUS_MODEL=xcoffee-coding
export ANTHROPIC_DEFAULT_HAIKU_MODEL=xcoffee-coding
Troubleshooting
- For
Model isn't recognized, check the group and protocol. The client's assumed context size is not a capacity guarantee from XCoffee. - For conflicting authentication sources, inspect
ANTHROPIC_API_KEY,ANTHROPIC_AUTH_TOKENand the settings file before replacing keys. - If an upstream rejects experimental tool fields, use this narrower troubleshooting launch only when needed:
env -u ANTHROPIC_API_KEY \
ANTHROPIC_BASE_URL=https://api.xcoff.ee \
ANTHROPIC_AUTH_TOKEN="$XCOFFEE_API_KEY" \
ENABLE_TOOL_SEARCH=false \
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 \
claude --model xcoffee-coding
Check a basic reply, reading a test file, and creating then reading a file before using real projects. Available features still depend on the upstream and client version.
Codex CLI: a separate profile and launch
1. Check the version and protocol
Install Codex CLI using the official OpenAI quickstart, then run codex --version. Choose OpenAI Responses in your XCoffee API console and confirm the group name. The separate profile below is for Codex CLI 0.134.0 and later.
2. Create your XCoffee profile file
Create ~/.codex/xcoffee.config.toml (%USERPROFILE%\.codex\xcoffee.config.toml on Windows). Back up and merge an existing file rather than duplicating table declarations. Replace xcoffee-coding with an available Responses group:
model = "xcoffee-coding"
model_provider = "xcoffee"
model_reasoning_effort = "medium"
[model_providers.xcoffee]
name = "XCoffee"
base_url = "https://api.xcoff.ee/v1"
env_key = "XCOFFEE_API_KEY"
wire_api = "responses"
requires_openai_auth = false
supports_websockets = false
Use top-level settings in this file, not a [profiles.xcoffee] wrapper. Current --profile reads the separate file. env_key is an environment-variable name, not the actual key; you do not need to rewrite auth.json.
3. Set the key and launch
Set XCOFFEE_API_KEY in the same terminal using the steps above, enter a test directory, then run:
codex --profile xcoffee
The launch command is the same in PowerShell. Start a new session, ask for one short reply, test reading and writing a test file, then check XCoffee request history.
To enable web search, add --search. It is a top-level option and must come before exec (codex exec --search fails).
Interactive:
codex --profile xcoffee --search
Non-interactive:
codex --profile xcoffee --search exec "…"
This profile applies when you select it. Keep using your original launch method for your global default. Older clients and surfaces requiring a global provider can use the same settings merged into user-level ~/.codex/config.toml, followed by codex, but this changes the global default. Do not put credential routing in a project's .codex/config.toml.
Troubleshooting
401: check that the terminal starting Codex hasXCOFFEE_API_KEYand that it is your XCoffee customer key.- Unsupported model or endpoint: confirm Responses is enabled for the group. This Codex configuration does not use Chat Completions.
- Requests still use another provider: check
--profile xcoffeeand any extra command-line overrides. - XCoffee uses HTTP Responses, so WebSocket transport is disabled in the example. Send complete history;
previous_response_idand stored upstream conversations are unavailable. Do not copy official model context sizes into a group configuration.
Client subagents and local tools differ from provider-hosted tools. Multiple agents share account credits and concurrency. See the supported-scope section and your dashboard for search and other additional capabilities.
OpenClaw: add an XCoffee provider
- Install OpenClaw and run
openclaw --version. Back up your~/.openclaw/openclaw.jsonfirst. - Choose Chat Completions in the API console and confirm the group name.
- Merge this into existing configuration, preserving other providers, agents and channels. Replace the example
xcoffee-codingwith your available group:
{
"models": {
"mode": "merge",
"providers": {
"xcoffee": {
"baseUrl": "https://api.xcoff.ee/v1",
"api": "openai-completions",
"apiKey": {
"source": "env",
"provider": "default",
"id": "XCOFFEE_API_KEY"
},
"models": [{ "id": "xcoffee-coding", "name": "XCoffee Coding" }]
}
}
},
"agents": {
"defaults": {
"model": { "primary": "xcoffee/xcoffee-coding" }
}
}
}
xcoffee/ is OpenClaw's internal provider prefix; the model sent to XCoffee is still xcoffee-coding. The SecretRef reads a local environment variable rather than storing the real key in JSON. Make XCOFFEE_API_KEY available to the process actually running OpenClaw.
- Start or restart OpenClaw using your existing setup. If its Gateway runs as a service, configure the variable for that service; exporting it in a different terminal does not update an already running service.
- Check configuration and model inventory with these commands, then test a new conversation, including a basic reply and local tools:
openclaw models status
openclaw models list
A status or inventory check does not establish that generation works. An agent-level model allowlist or a session model override may also need xcoffee/xcoffee-coding selected. Use the group's actual context and image capabilities rather than copying another provider's numbers.
Hermes: terminal and Telegram configuration
Exit the current Hermes session, then run:
hermes model
- Choose
Custom endpoint, not ChatGPT subscription or official Anthropic login. - Enter
https://api.xcoff.ee/v1as the Base URL and your customer key as the API key. - If asked for transport, select
chat_completions. Usexcoffee-codingor another available group from your API console. - Leave context length blank initially for discovery. A displayed 256K fallback does not establish every group member's actual capacity.
- Save, run
hermes, and test a new session.
Versions supporting named providers also allow this alternative: back up ~/.hermes/config.yaml and merge the entry into its existing providers. It uses the environment variable set earlier:
providers:
xcoffee:
api: https://api.xcoff.ee/v1
key_env: XCOFFEE_API_KEY
transport: chat_completions
default_model: xcoffee-coding
Use /model to select the XCoffee group. For Telegram, configure the machine and configuration directory running the Hermes gateway, not just another computer. Provide the variable to the gateway service; a terminal export does not update an already running service. Restart the gateway through your existing service manager and test a new session, since old sessions may retain their own model selection. Store the key locally; never send it to the Telegram Bot.
Pi: add custom groups
This section refers to the pi-mono coding agent. Set XCOFFEE_API_KEY above, then back up and edit ~/.pi/agent/models.json (or the file in your custom agent directory). Merge xcoffee into existing providers, preserving other providers:
{
"providers": {
"xcoffee": {
"baseUrl": "https://api.xcoff.ee/v1",
"api": "openai-completions",
"apiKey": "${XCOFFEE_API_KEY}",
"models": [
{ "id": "xcoffee-coding", "name": "XCoffee Coding" },
{ "id": "xcoffee-fast", "name": "XCoffee Fast" },
{ "id": "xcoffee", "name": "XCoffee" }
]
}
}
}
Keep only the groups available in your API console. apiKey references the environment variable; do not replace it with a real secret in the file. Run pi and select XCoffee with /model; reopening the picker reloads model configuration. Do not copy another model's context or image capabilities. Use the group's published capabilities where explicit metadata is needed.
Cursor: check for a custom endpoint option first
- Open Cursor Settings → Models and locate API-key settings.
- If your version offers an OpenAI Base URL override or custom provider, enter
https://api.xcoff.ee/v1and your customer key. - If custom model names can be added, add an available group such as
xcoffee-coding, then select it in the chat model picker. - Test a fresh conversation using the three tasks below. Successful key verification alone does not verify editing or tool execution.
If these custom settings are absent, do not enter your XCoffee key against an official provider endpoint. Cursor's official BYOK documentation does not guarantee arbitrary third-party group IDs. These are conditional setup instructions, not complete XCoffee/Cursor certification. Custom keys do not replace Cursor Tab's built-in models. Agent, reasoning models and other specialized features depend on your Cursor version and supported scope. Requests pass through Cursor's backend rather than connecting entirely from your local machine.
Verify the setup with three small tasks
Start your Agent in an empty test directory and send these prompts in order:
- “Reply only: connection successful.” This checks basic conversation.
- “List the files in this test directory.” This checks local tool calling.
- “Create hello.txt containing Hello XCoffee, then read it back.” Approve the test-file operation when your client asks.
Then check that key's request history and credits in the user center. A text response alone does not prove that tools work. For errors, share the client version, time, group and error code or request ID. Never include your key or a private conversation transcript.
Ask your Agent to configure the connection
Send this to an Agent that can read webpages and edit local configuration. Replace “my client” with Claude Code, Codex or your chosen tool:
Read https://api.xcoff.ee/guide and help connect "my client" to XCoffee.
Check the client version and back up configuration first. Change only connection settings and preserve other providers.
Use xcoffee-coding if available in my API console; otherwise ask me to choose an available group.
I will set XCOFFEE_API_KEY locally. Do not read, display or ask me to paste my key.
Follow the guide's protocol and URL settings. Do not invent a context size or disable tool-operation approval prompts.
Explain how to launch and verify the setup. Do not modify or deploy other projects.
This is an instruction for your Agent, not a webpage installer that changes your computer automatically.
Protocols and addresses
Replace https://YOUR_HOST with this site’s origin and YOUR_GROUP with an available group name. Endpoints have no language prefix.
| Protocol | Client Base URL | Generation endpoint | Key header |
|---|---|---|---|
| OpenAI Chat Completions | https://YOUR_HOST/v1 | /v1/chat/completions | Authorization: Bearer YOUR_KEY |
| OpenAI Responses | https://YOUR_HOST/v1 | /v1/responses | Authorization: Bearer YOUR_KEY |
| Anthropic Messages | https://YOUR_HOST | /v1/messages | x-api-key: YOUR_KEY |
| Gemini native | https://YOUR_HOST | /v1beta/models/YOUR_GROUP:generateContent | x-goog-api-key: YOUR_KEY |
JSON and SSE streaming are available. Anthropic also accepts Bearer authentication and requires an anthropic-version header (default 2023-06-01). Gemini streaming uses :streamGenerateContent?alt=sse; put the key in a header, not a URL query. Model discovery uses /v1/models or /v1beta/models and requires your key.
The administrator must enable each supported API on its upstream. Existing upstreams default to Chat Completions; adding website endpoints does not give a Chat-only provider native APIs. The user center lists the groups available for your selected protocol. Client-side function/tool calls and structured fields are forwarded; specific model support still varies.
Responses example
curl https://YOUR_HOST/v1/responses \
-H "Authorization: Bearer $CUSTOMER_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"YOUR_GROUP","input":"Hello","max_output_tokens":128,"stream":true,"store":false}'
Anthropic example
curl https://YOUR_HOST/v1/messages \
-H "x-api-key: $CUSTOMER_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{"model":"YOUR_GROUP","messages":[{"role":"user","content":"Hello"}],"max_tokens":128,"stream":true}'
Gemini example
curl 'https://YOUR_HOST/v1beta/models/YOUR_GROUP:streamGenerateContent?alt=sse' \
-H "x-goog-api-key: $CUSTOMER_KEY" \
-H "Content-Type: application/json" \
-d '{"contents":[{"role":"user","parts":[{"text":"Hello"}]}],"generationConfig":{"maxOutputTokens":128}}'
Client settings and supported scope
Clients such as Codex, Claude Code and Gemini CLI must be configured to use the matching HTTP protocol, a custom provider URL and an available group name. Set an output budget appropriate for the selected upstream model. The site supports these API paths, not every feature of every CLI version.
The default output budget is 4096 tokens. Default group caps are 128,000 for coding, 32,000 for fast and 64,000 for xcoffee; the operator may configure them. Lower upstream limits still apply, independently of context length. Larger requested budgets are clamped. Chat uses max_tokens or max_completion_tokens, Responses uses max_output_tokens, Anthropic uses max_tokens, and Gemini uses generationConfig.maxOutputTokens. Explicit reasoning effort is capped at medium; lower choices are preserved. Numeric thinking budgets have a separate cap. No reasoning parameters are added when reasoning is not enabled. Upstream default reasoning without an exposed control remains upstream-managed. Reported reasoning tokens are included in output once.
Send full conversation history. Responses always forwards store:false; previous_response_id, saved conversations, background execution and shared upstream file references are unavailable. Encrypted reasoning items carried by the client can be forwarded. Web search is supported only on Responses (web_search, Codex) and Anthropic (web_search_*, Claude Code). Each search the gateway reports costs 1 credit in addition to tokens, up to 50 searches per UTC day. Chat web_search_options and Gemini googleSearch / googleSearchRetrieval are removed before forwarding, with the rest of the request kept. Gemini stored caches and remote file references, Anthropic server-managed containers/MCP, web_fetch, code execution, file upload APIs, image generation and WebSocket transport are outside this endpoint set. Inline content still depends on the upstream model.
Shared usage and limits
All keys, protocols and groups share daily account credits, rolling hourly credits, request rate and concurrency. See your user dashboard for current daily and rolling-hour allowances. Daily credits reset at UTC 00:00 without carryover. Daily and rolling-hour allowances are set separately by the purchased plan, not calculated from the remaining daily balance. Requests spanning midnight belong to the UTC date they started; rolling hourly usage does not reset. Pausing, deleting or rotating keys does not reset usage or extend expiry.
Concurrency and per-minute or other rolling-window request/token limits vary by purchased plan; use the terms confirmed at purchase and active rights shown in your dashboard. All keys share the limits and a stream holds its slot until it ends. Where weighted requests apply, total input including cache costs 1 unit at or below 32,000 tokens, 2 above that, and 4 above 80,000. Input and output credits are reserved before forwarding and reconciled on completion. Historical calls are not retrospectively charged or repriced.
Credits = (uncached input + cache reads × cache factor + output × output factor) ÷ billable tokens per credit × group multiplier, plus 1 credit for each web search reported on Responses or Anthropic. See the user dashboard for current rates, allowances and today's search count, and the homepage model groups for group multipliers. Cache writes are full price; missing cache details receive no discount. Anthropic cache reads and writes are included in normalized total input; Gemini cache is already part of prompt input. Reported reasoning counts as output once. Credits display two decimals and are stored at 10^-8 precision. Token-counting endpoints cost no credits, while still consuming request and concurrency allowance. The search cap is 50 per account per UTC day and applies to Responses and Anthropic only; a request that starts under the cap can finish slightly above it.
POST /v1/messages/count_tokens and POST /v1beta/models/YOUR_GROUP:countTokens require the administrator to enable native token counting on that upstream. They use your key and group permissions and consume request allowance and a concurrent slot, but no generation tokens. Counts are the upstream’s estimate.
Explicit pre-generation rejections consume a request but no tokens. Interrupted calls or missing usage retain a conservative estimate; they are not free. See remaining days, today’s total and per-key usage in the user center.
Within one group, an explicit pre-generation rejection (401/403/404/405/429) can try another configured upstream, up to three distinct targets in total. The request keeps one allowance reservation and ledger entry. Network errors, 5xx, cancellation and responses that have started are never automatically replayed; Magpie’s own model-group routing is configured separately.
Errors and support
Check key and pass status for 401; group permission for 403; account or upstream limits for 429; upstream availability, protocol compatibility and timeout for 502/503/504. Blind retries after partial output may consume usage again.
Submit timestamps and request IDs through support in the user center. Never include keys or sensitive full prompts.
Official references and update date
Client configuration references were checked on November 7, 2026. Your XCoffee API console remains the source for available groups, protocols and allowances.