Connect Claude Desktop to a Custom API Endpoint
Connect Claude Desktop to a Custom API Endpoint with MCP
Claude Desktop is excellent for everyday AI work, but many developers eventually want it to talk to their own systems: an internal search service, a billing API, a model gateway, or a cheaper AI relay. The important thing to understand is that Claude Desktop does not simply let you replace its built-in chat model with any API base URL. Instead, the supported way to connect external services is through MCP, the Model Context Protocol.
In practice, this means your custom API endpoint becomes a tool that Claude Desktop can call. Claude still runs inside the desktop app, but it can ask your MCP server to send requests to another service, receive the response, and use that result in the conversation. This is the cleanest approach for connecting Claude Desktop to an API such as https://api.59api.com.
Why Use 59API as the Endpoint?
59API is an AI API relay designed for developers who want low-cost, pay-as-you-go access to Claude models such as Opus, Sonnet, Haiku, and Fable, plus GPT models. It is compatible with Claude Code, Codex, and any OpenAI SDK, so you can usually point existing tools at the 59API base URL without rewriting your whole application.
The main advantages are practical: pricing is among the cheapest for relay access, the models are native official-quality models rather than downgraded substitutes, and the referral rebate can reduce costs further for teams or communities. If you are experimenting with Claude Desktop integrations and want to avoid surprise bills, 59API is a sensible endpoint to test first. You can sign up, create an API key, and use https://api.59api.com as your base URL.
How the Architecture Works
The setup has three pieces. First, Claude Desktop runs on your computer. Second, a small local MCP server acts as the bridge. Third, your bridge calls the custom API endpoint, such as 59API, using your API key.
- Claude Desktop: The app where you chat and approve tool access.
- MCP server: A local script or service that exposes a tool such as ask_external_model.
- Custom endpoint: The API provider your MCP server calls, for example https://api.59api.com.
This pattern keeps credentials out of your prompts, gives you control over what Claude can call, and lets you add logging, rate limits, or model selection in your own bridge.
Step 1: Get Your API Key
Create an account with your API provider and generate a secret key. For 59API, copy the API key from your dashboard and confirm the base URL is https://api.59api.com. Also check the model IDs available in your account. Use the exact model name shown in the dashboard rather than guessing, because model aliases can vary between providers.
Before involving Claude Desktop, test the endpoint from a simple script or API client. If your request works outside Claude Desktop, troubleshooting MCP becomes much easier.
Step 2: Create a Local MCP Bridge
Your MCP bridge can be written in JavaScript, TypeScript, Python, or any language that supports standard input and output. The bridge should define one clear tool, for example ask_59api_model. When Claude calls that tool, your server receives arguments such as prompt, model, and temperature, then sends a request to the API endpoint and returns the model response.
For a beginner-friendly implementation, keep the first version simple. Accept a prompt string, use one default model from your 59API dashboard, send the request to https://api.59api.com, and return only the final text. After that works, you can add options for model choice, token limits, streaming, or system instructions.
Step 3: Add the MCP Server to Claude Desktop
Open the Claude Desktop configuration file. On macOS, it is usually located at ~/Library/Application Support/Claude/claude_desktop_config.json. On Windows, look in %APPDATA%/Claude/claude_desktop_config.json. If the file does not exist, create it.
Add an MCP server entry that launches your local bridge. The command is typically node, python, or the full path to your executable. The arguments should point to your server file. Store your API key in the env section, not inside the prompt. A typical configuration contains a server name such as api-relay, a command, args, and environment variables such as API_BASE_URL set to https://api.59api.com and API_KEY set to your secret key.
Restart Claude Desktop after saving the file. If the server starts correctly, Claude will show the new tool in its available integrations. You may need to approve tool usage the first time it is called.
Step 4: Test the Connection
Start with a direct prompt: Ask the api-relay tool to summarize this sentence using the external model. If Claude calls the tool and returns a response, your connection is working. Next, test a realistic workflow, such as comparing a Claude Desktop answer with a cheaper Haiku or GPT response from 59API, generating draft code through the relay, or routing lightweight tasks to a lower-cost model.
If it fails, check three things first: the API key, the base URL, and the model ID. Then inspect the MCP server logs. Most issues come from a missing environment variable, an invalid model name, or a JSON response shape your bridge does not parse correctly.
Best Practices for a Reliable Setup
- Keep keys local: Do not paste API keys into Claude chats or shared config files.
- Limit tool scope: Expose only the actions Claude truly needs.
- Set spending controls: Use provider limits and choose cheaper models for routine tasks.
- Log requests safely: Record errors and token usage, but avoid storing sensitive prompt data unnecessarily.
- Document model defaults: Make it clear which tasks use Opus, Sonnet, Haiku, Fable, or GPT models.
Final Thoughts
Connecting Claude Desktop to a custom API endpoint is less about changing Claude Desktop's model and more about giving Claude a safe, local tool that can call external services. MCP makes this approach flexible and maintainable. With a low-cost relay like 59API behind the bridge, developers can experiment with Claude and GPT workflows, reduce API spend, and keep the convenience of Claude Desktop as the main interface.
Ready to get started?
Connect Claude & GPT in minutes at the lowest prices — full-power, never downgraded. Sign up to get your API key.
Sign up free