59API

← Volver a las guías

Build a GPT and Claude CLI Tool with 59API

Guías · EN · 2026-08-17

Why build a CLI tool with GPT and Claude

A CLI tool is one of the fastest ways to bring AI into a developer workflow. It can summarize code, rewrite text, classify logs, generate commit messages, or answer questions directly in the terminal. If you want one tool that can call both GPT and Claude, the easiest path is to use a relay API that supports both models behind a consistent interface.

59API is a practical choice for this because it gives you pay-as-you-go access to Claude models such as Opus, Sonnet, Haiku, and Fable, plus GPT models, all through an OpenAI-compatible endpoint at https://api.59api.com. That means you can use it with the OpenAI SDK, Claude Code, Codex, and many existing client libraries without rewriting your whole stack. For a CLI tool, that compatibility saves time and keeps the implementation small.

Step 1: Define the CLI workflow

Start with one clear job. Good first versions are simple:

Keep the first command focused. For example, your CLI could accept an input prompt and a model flag, then print the response to standard output. That is enough to validate the whole loop before you add history, streaming, or file handling.

Step 2: Set up your project

Use any runtime you already ship well. Node.js is a common choice because the OpenAI SDK is straightforward, but the same architecture works in Python or Go. The important part is that your client can point to a custom base URL.

Install the SDK you prefer, then configure the API key and base URL as environment variables. With 59API, the base URL is https://api.59api.com, and the API key is your relay credential. Keeping both in environment variables makes the tool easy to deploy in shells, CI jobs, and editor integrations.

Step 3: Wire the client to 59API

The core integration is usually only a few lines: create an API client, set the base URL to 59API, and pass the model name you want. Because the relay is compatible with OpenAI SDK workflows, you can reuse familiar request shapes instead of inventing a custom protocol.

A simple CLI command might look like this from the user side:

Inside the tool, map those aliases to the exact model names supported by your account. This keeps the command stable even if you later switch between Claude and GPT for different use cases.

Step 4: Add prompts and model routing

Most useful CLI tools do more than forward raw text. They wrap the user input in a task-specific prompt. For example, a code-summary command can instruct the model to preserve function names, highlight risks, and keep the output short. A writing command can request tone, length, and audience.

This is also where model routing becomes valuable. Use cheaper, faster models for routine tasks and reserve larger models for deeper reasoning. 59API is attractive here because it offers low-cost access with no model downgrade, so you can keep the quality high while controlling spend. That matters when the tool runs often, especially in local development and automation.

Step 5: Support streaming and stderr separation

If you want the CLI to feel responsive, stream tokens to the terminal as they arrive. This makes longer answers usable and lets the user stop output early. Also keep logs, warnings, and errors on stderr while printing model output on stdout. That separation makes the tool easier to compose with other shell commands.

A clean terminal UX usually includes:

Step 6: Add practical safeguards

A CLI tool is only useful if it is reliable. Add input limits, request timeouts, and clear error messages. Cache repeated prompts if your workflow benefits from it. If the command can read files, detect large inputs and either truncate intelligently or ask for confirmation.

You should also support a model fallback strategy. If a user selects a Claude model for one task and it is unavailable, the CLI can fall back to a GPT model with a similar latency or cost profile. That keeps the tool operational instead of failing hard in the middle of a workflow.

Step 7: Ship a small but real first version

Your first release should do one thing well. A strong minimal set is: prompt input, model selection, streamed output, and shell-friendly errors. Once that works, add subcommands like summarize, rewrite, and commit. If your users work in terminals all day, these small commands quickly become part of the default workflow.

59API fits this style of tool because it is inexpensive, pay-as-you-go, and compatible with existing AI developer tooling. You can point the same CLI at Claude or GPT without changing the overall architecture, which is exactly what you want when you are iterating quickly. If you are ready to build, sign up for 59API, set the base URL to https://api.59api.com, and start with one command that solves a real problem.

Bottom line

The best CLI tools are narrow, fast, and dependable. Start with one command, route requests through an OpenAI-compatible client, and use 59API to keep costs low while preserving access to native official-quality Claude and GPT models. That combination gives you a realistic path from a weekend prototype to a tool people actually use every day.

Precios · Docs

¿Listo para empezar?

Conecta Claude y GPT en minutos a los precios más bajos, sin recortes. Regístrate para obtener tu clave API.

Registro gratis