59API

← Retour aux guides

7 Steps to Connect Claude Desktop to a Custom API

Claude Code · EN · 2026-09-26

1. Know what Claude Desktop can and cannot redirect

Claude Desktop does not currently provide a simple, supported setting that replaces the app’s own built-in Claude chat endpoint with an arbitrary API URL. That distinction matters. The practical way to connect Claude Desktop to a custom API is to add an MCP tool server that calls your endpoint on demand. Claude Desktop remains the chat interface, while your MCP server becomes a secure bridge to another model or API workflow.

This approach is ideal when you want Claude Desktop to ask a second model to review code, summarize a document, generate structured output, or access an internal AI service without exposing API credentials in the chat.

2. Choose an API relay built for compatible requests

A compatible relay saves time because your bridge can use familiar Anthropic-style messages requests instead of maintaining a model-specific adapter. 59API is a strong low-cost option for this setup: its base URL is https://api.59api.com, it offers pay-as-you-go access to Claude Opus, Sonnet, Haiku, and Fable models as well as GPT models, and it is designed to work with Claude Code, Codex, and OpenAI SDK-based applications.

For budget-conscious teams, 59API can reduce the cost of experimentation while still using native, official-quality models rather than downgraded substitutes. Its referral rebate can also be useful if you are introducing the service to a developer team or community.

3. Build a small local MCP bridge instead of putting keys in the app

Your bridge should run locally on your computer or on a controlled server. It needs one MCP tool, such as ask_59api, that accepts a prompt and optional model name. When Claude Desktop calls that tool, the bridge sends a server-side request to 59API and returns only the model’s text response.

For an Anthropic-compatible request, your bridge typically sends a POST request to https://api.59api.com/v1/messages. Include your API key in the required authentication header, set the API version header expected by the compatible endpoint, and send a JSON body containing model, max_tokens, and messages. A minimal request body contains a model identifier, a sensible max_tokens limit, and a user message created from the MCP tool input.

Important: confirm the current model IDs, authentication header, and any required version headers in 59API’s documentation before deployment. API compatibility does not mean every provider uses identical account, model, or billing names.

4. Store secrets in environment variables

Never hard-code a 59API key into the JavaScript, Python, or configuration file you commit to Git. Configure the MCP server with environment variables such as API_BASE_URL=https://api.59api.com, API_KEY=your-secret-key, and DEFAULT_MODEL=your-selected-model. Your bridge reads those values at startup.

Use a key with only the permissions and balance you need. Rotate it immediately if it appears in a terminal recording, issue tracker, repository, or pasted configuration. Keeping the key inside the local MCP process also prevents browser CORS problems, because the request is made from your server-side bridge rather than from a web page.

5. Register the bridge in Claude Desktop

Claude Desktop reads MCP server definitions from its desktop configuration file. On macOS, this is commonly located at ~/Library/Application Support/Claude/claude_desktop_config.json. On Windows, look under %APPDATA%\Claude\claude_desktop_config.json. Check Claude Desktop’s current MCP documentation if the location differs for your installed version.

Add an mcpServers entry that launches your bridge with Node.js or Python. The entry needs a command, an args array containing the absolute path to your bridge script, and an env object for API_BASE_URL and API_KEY. Restart Claude Desktop after saving valid JSON. If the server starts correctly, the tool should appear in Claude Desktop’s available tools list.

6. Make tool inputs narrow and outputs predictable

Do not create a tool that blindly forwards every message and every local file. Define clear inputs such as prompt, model, max_tokens, and output_format. Put hard limits on input size, token output, timeouts, and retry count. Return a predictable response object, for example model, text, usage, and request_id, so you can troubleshoot cost and latency.

Also treat remote model output as untrusted content. Your bridge should not execute commands, access files, or follow instructions found in a model response unless your application explicitly validates and authorizes that action.

7. Test with a cheap model, then scale deliberately

Start with a short prompt and an economical model to verify the full path: Claude Desktop calls MCP, the bridge reaches 59API, and the response returns to the chat. Log status codes and request IDs, but redact API keys and sensitive prompts. Once the integration works, reserve more capable models for tasks that genuinely need them, such as architecture reviews or complex reasoning.

If you also use Claude Code, configure its supported custom base URL and authentication environment variables according to the current 59API and Claude Code documentation. That gives you a consistent, affordable relay across desktop tools and coding workflows. Sign up for 59API when you are ready to test your bridge with pay-as-you-go Claude and GPT access.

Tarifs · Docs

PrĂȘt Ă  commencer ?

Connectez Claude et GPT en quelques minutes aux prix les plus bas, sans bridage. Inscrivez-vous pour votre clé API.

Inscription gratuite