59API

← 返回教程列表

Claude Desktop Custom API Setup: A 2026 MCP Guide

Claude Code · EN · 2026-10-18

Understand what Claude Desktop can connect to

Connecting Claude Desktop to a custom API endpoint requires understanding two separate connections. The standard desktop app does not provide a documented, general-purpose base URL setting for replacing its built-in Claude service. It can, however, call an external API through a local Model Context Protocol (MCP) server.

This 2026 guide builds that connection using 59API. Claude Desktop will receive an ask_59api tool that sends a prompt to your chosen model. Your desktop conversation still uses Anthropic’s service; only the tool’s request goes through 59API. Desktop access and API usage have separate billing.

Choose and verify your 59API endpoint

59API offers inexpensive, pay-as-you-go access to Claude and GPT models, with OpenAI SDK compatibility and support for developer tools including Claude Code and Codex. Its API origin is https://api.59api.com. Confirm the documented versioned path before configuring a client; an OpenAI-compatible deployment commonly uses https://api.59api.com/v1.

Create an API key and copy an exact model identifier from your dashboard. Display names and API identifiers can differ. If supported by your account, this request lists available models:

curl https://api.59api.com/v1/models -H "Authorization: Bearer YOUR_59API_KEY"

Run credential-bearing commands only in a trusted environment, and keep keys out of shared terminal recordings. Check current input and output prices for your chosen model. 59API positions itself among the cheapest relays and describes its models as native, official-quality versions without downgrading; verify the specific model offering against your workload.

Create a minimal local MCP server

Install a current Node.js LTS release. In a dedicated folder, run npm init -y, followed by npm install @modelcontextprotocol/sdk zod. Create a plain-text file named 59api.key containing only your API key. Restrict its permissions to your user account; on macOS or Linux, run chmod 600 59api.key.

Create relay.mjs in the same folder using the following lines, placing each paragraph on its own line. Replace YOUR_MODEL_ID with the exact identifier you verified:

import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';

import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

import { z } from 'zod';

import { readFileSync } from 'node:fs';

const key = readFileSync(new URL('./59api.key', import.meta.url), 'utf8').trim();

const server = new McpServer({ name: '59api-relay', version: '1.0.0' });

server.registerTool('ask_59api', { description: 'Send a prompt to the configured 59API model', inputSchema: { prompt: z.string() } }, async ({ prompt }) => { const response = await fetch('https://api.59api.com/v1/chat/completions', { method: 'POST', headers: { Authorization: 'Bearer ' + key, 'Content-Type': 'application/json' }, body: JSON.stringify({ model: 'YOUR_MODEL_ID', messages: [{ role: 'user', content: prompt }], max_tokens: 512 }), signal: AbortSignal.timeout(60000) }); if (!response.ok) throw new Error('Upstream HTTP ' + response.status); const data = await response.json(); return { content: [{ type: 'text', text: data.choices?.[0]?.message?.content || 'No text returned' }] }; });

await server.connect(new StdioServerTransport());

Register the server in Claude Desktop

Open Claude Desktop’s developer settings and use its configuration editor. The local configuration file is typically ~/Library/Application Support/Claude/claude_desktop_config.json on macOS or %APPDATA%\Claude\claude_desktop_config.json on Windows.

Add this entry, merging it with existing servers. Replace both paths with absolute paths; Windows JSON paths require escaped backslashes.

{ "mcpServers": { "59api": { "command": "/absolute/path/to/node", "args": ["/absolute/path/to/relay.mjs"] } } }

Fully quit and reopen Claude Desktop. Enable the tool, then ask: “Use ask_59api to explain HTTP caching in three sentences.” Approve the tool call when prompted.

Check costs, errors, and data flow

Only the supplied tool prompt reaches 59API through this script; it does not automatically forward conversation history or attachments. Start with non-sensitive prompts and a small spending budget. Sign up for 59API when you are ready to test its pricing, and check its referral rebate terms for additional savings.

价格 · 接入文档

准备好开始了吗?

几分钟接入 Claude 与 GPT,全网超低价,原生不降智。立即注册即可领取 API 密钥。

免费注册