api2cli: Turn Any API into a Claude‑Powered CLI in Minutes

Imagine asking your AI assistant to send an email, manage customer domains, or fetch user data—just by talking. No writing code, no reading API docs, no copying curl commands. That’s exactly what api2cli delivers.

Built as a skill for Claude Code, api2cli automatically converts any API—whether it has documentation, a live endpoint, or even just network traffic captures—into a fully functional command‑line interface (CLI). Then it wraps that CLI in a “skill” so Claude can use it again in any future session without ever looking at the code.

In this guide, we’ll explore how api2cli works, walk through real examples, and show you why this “agent‑first” approach is changing how developers and AI collaborate.


What Is api2cli?

api2cli is a Claude Code skill that:

  1. Discovers API endpoints from documentation pages, live API probing, or peek‑api network captures.
  2. Generates a production‑ready CLI with one subcommand per endpoint, built on Commander.js.
  3. Creates a reusable skill (a SKILL.md file) that teaches Claude how to use the CLI—commands, examples, and common workflows.

Once generated, any Claude session in your project can instantly call your API through simple, intuitive commands. The AI doesn’t need to understand authentication, pagination, or rate limits—it just runs the CLI.


Why an API‑to‑CLI Tool Matters

Let’s say you want to use the Resend email API to send a message. Normally you’d:

  • Read through API docs to find the right endpoint.
  • Write code (or a curl command) with headers, authentication, and body.
  • Handle errors, retries, and maybe pagination.
  • Repeat the whole process if you switch projects or want to automate a new task.

With a CLI, that workflow becomes:

resend emails send --to user@example.com --subject "Hello" --html "<p>Hi</p>"

But here’s the real magic: AI agents can run that same command. Claude can send emails, check delivery status, manage domains—all by itself. And because api2cli also generates a skill, Claude will know about this CLI in every future conversation, without you having to remind it.


Real‑World Example: The Resend Email API

To see api2cli in action, let’s walk through what happens when you ask Claude to build a CLI for the Resend API.

Your request:

“Build me a CLI for the Resend API. Here are the docs: https://resend.com/docs/api-reference”

Step 1 – Discovery

Claude visits the documentation and identifies all available endpoints. It reports back:

Found 15 endpoints across 5 resources:
  emails (3 endpoints): send, get, batch
  domains (4 endpoints): list, get, create, delete
  api-keys (3 endpoints): list, create, delete
  audiences (3 endpoints): list, get, create
  contacts (2 endpoints): list, create

Ready to generate the CLI?

Step 2 – CLI Generation

Claude creates a TypeScript CLI at scripts/resend.ts using Commander.js. You can immediately run it:

# See all commands (self‑documenting)
npx tsx scripts/resend.ts

Output:

{
  "ok": true,
  "command": "resend",
  "result": {
    "description": "Resend email API CLI",
    "commands": [
      { "command": "resend emails send", "description": "Send an email" },
      { "command": "resend emails get <id>", "description": "Get email by ID" },
      { "command": "resend domains list", "description": "List all domains" }
    ]
  }
}

Step 3 – Human‑Friendly Output

Run a command directly in your terminal, and you get a clean, human‑readable table:

npx tsx scripts/resend.ts domains list
ID          Domain              Status
re_abc123   example.com         verified
re_def456   staging.example.com pending

Step 4 – Agent‑Friendly Output

Pipe the same command (or run it in a non‑TTY environment), and the CLI automatically switches to JSON, complete with next_actions suggestions:

npx tsx scripts/resend.ts domains list | cat
{
  "ok": true,
  "command": "resend domains list",
  "result": { "domains": [...], "count": 2 },
  "next_actions": [
    { "command": "resend domains get re_abc123", "description": "View domain details" },
    { "command": "resend emails send --from noreply@example.com", "description": "Send from verified domain" }
  ]
}

Step 5 – Skill Generation

Finally, Claude creates a skill file at .claude/skills/resend/SKILL.md:

---
name: resend
description: Interact with the Resend email API via CLI. Use when user wants to
  send emails, manage domains, create API keys, manage audiences and contacts.
---

# Resend CLI

## Setup
export RESEND_API_KEY=re_your_key_here

## Commands
### emails send --to <email> --subject <text> --html <html>
### domains list | get <id> | create --name <domain>
### contacts list --audience-id <id> | create --email <email>
...

Now, any future Claude session in your project can use the Resend CLI without reading code or docs. Just mention “send an email,” and Claude knows exactly what to do.


How API Discovery Works

api2cli supports three discovery methods, each suited to different situations:

Method Best For How It Works
Docs Parsing Public APIs with online documentation Crawls and analyzes documentation pages, extracting endpoints, methods, parameters, and authentication details.
Active Probing APIs where you have a base URL and credentials Sends lightweight probe requests (e.g., GET /, OPTIONS) to discover available endpoints based on common REST patterns.
peek‑api Capture Internal or undocumented APIs Works with peek‑api to capture network traffic from a web app and reconstruct API endpoints.

During discovery, api2cli builds a detailed endpoint catalog that includes:

  • Resource names (e.g., emails, domains)
  • HTTP methods and URL paths
  • Required and optional parameters
  • Authentication type (API key, OAuth, etc.)
  • Pagination support and parameter names
  • Documented rate limits
  • Sample response structures (used for generating next_actions)

You get to review this catalog before generation, ensuring everything is accurate.


Inside the Generated CLI

The CLI produced by api2cli is no quick‑and‑dirty script. It’s a robust tool with features you’d expect from a production‑grade client.

Built with Commander.js

Each API endpoint becomes a subcommand, organized by resource:

resend
  ├── emails
  │   ├── send
  │   ├── get <id>
  │   └── batch
  ├── domains
  │   ├── list
  │   ├── get <id>
  │   ├── create --name <domain>
  │   └── delete <id>
  └── ...

Dual‑Mode Output

  • Human mode (terminal): Pretty‑printed tables, colors, and summaries.
  • Agent mode (piped/redirected): Clean JSON with ok status, result data, and next_actions for follow‑up steps.

The CLI detects whether it’s running interactively or being piped, switching modes automatically.

Intelligent API Client

Under the hood, a shared client handles:

  • Authentication – Reads API keys from environment variables (e.g., RESEND_API_KEY).
  • Retries with backoff – Retries failed requests up to 3 times with exponential delay (1s, 2s, 4s).
  • Rate limiting – Enforces documented limits using a token bucket algorithm.
  • Caching – Caches GET responses for 5 minutes (configurable).
  • Pagination – Fetches first page by default, with --all flag for complete results.

Error Handling with Fix Suggestions

When something goes wrong, the CLI outputs structured errors that help both humans and AI recover:

{
  "ok": false,
  "command": "resend emails send",
  "error": {
    "type": "authentication",
    "message": "Invalid API key",
    "fix": "Check that RESEND_API_KEY is set correctly in your environment"
  }
}

Next Actions for Autonomous Workflows

The next_actions array is inspired by HATEOAS (Hypermedia as the Engine of Application State). After each command, the CLI suggests logical next steps based on the result:

  • After listing domains, it suggests getting details of a specific domain.
  • After creating a domain, it suggests verifying it.
  • After sending an email, it suggests checking delivery status.

This turns a simple CLI into a guided experience—perfect for AI agents exploring an API.


The Skill: Teaching Claude to Use Your CLI

The SKILL.md file is what makes api2cli truly powerful. It lives in your project’s .claude/skills/ directory and contains:

YAML Front Matter

name: resend
description: Interact with the Resend email API via CLI. Use when user wants to
  send emails, manage domains, create API keys, manage audiences and contacts.
triggers:
  - send email
  - manage domain
  - email api

These triggers help Claude decide when to activate the skill.

Command Reference

A complete list of all subcommands, with parameters and examples:

## Commands

### `resend emails send`
Send an email.
- `--to <email>` – Recipient address
- `--subject <text>` – Email subject
- `--html <html>` – HTML content
- `--from <email>` – Sender (default: verified domain)
Example: `resend emails send --to user@example.com --subject "Hello" --html "<p>Hi</p>"`

Common Workflows

Multi‑step processes that combine several commands:

## Workflows

**Verify a new domain**
1. `resend domains create --name example.com`
2. `resend domains get example.com` – copy verification token
3. Add DNS record with your provider
4. `resend domains verify example.com`

Environment Setup

Clear instructions on what environment variables are needed and how to obtain them.

With this skill in place, Claude can autonomously perform complex tasks involving your API, and it will remember how in every session.


Installation and First Steps

Prerequisites

  • Claude Code enabled in your project (see official docs)
  • Node.js (for running the generated TypeScript CLI)

Install the api2cli Skill

# Clone the repository
git clone https://github.com/alexknowshtml/api2cli.git

# Copy the skill into your Claude project
cp -r api2cli/skill/ /path/to/your/project/.claude/skills/api2cli/

Once copied, Claude Code automatically loads the skill. You’re ready to generate CLIs.

Example Conversations

Generate from public docs:

“Build a CLI for the SendGrid API. Docs are at https://docs.sendgrid.com/api-reference”

Generate from a live API:

“I have an internal API at https://api.internal.example.com/v2. It uses Bearer tokens from INTERNAL_TOKEN. Can you make a CLI for it?”

Generate from a peek‑api capture:

“Here’s my peek‑api capture file capture.json. Turn this into a CLI.”

In each case, Claude will guide you through discovery, show you the endpoint catalog for confirmation, and generate both the CLI and skill.


Technical Deep Dive: Agent‑First Design Principles

api2cli follows a set of design principles that make generated CLIs ideal for AI consumption. These principles, inspired by Joel Hooks’ agent‑first CLI design, ensure seamless human‑AI collaboration.

1. Structured, Predictable Output

All output is either:

  • Human‑optimized (tables, summaries) for terminal use
  • Machine‑optimized (clean JSON) for AI use

No mixed formats, no ambiguous parsing.

2. Self‑Documenting Commands

Running a command without arguments always prints usage information in JSON format, so AI can dynamically discover available subcommands and parameters.

3. Recoverable Errors

Errors include enough context for AI to understand what went wrong and a fix field suggesting how to resolve it. This enables autonomous error recovery.

4. Context‑Safe Output

The CLI never assumes terminal features like colors or width. All output is plain text, ensuring AI can read it without corruption.

5. Safe by Default

Modifying commands (POST, PUT, DELETE) require confirmation unless --force is provided. This prevents accidental destructive actions by AI.

6. Next Actions for Exploration

The next_actions field turns static API responses into dynamic exploration paths, allowing AI to discover and execute multi‑step workflows naturally.


Use Cases: What Can You Build?

AI‑Powered Customer Support

Generate a CLI for your CRM API. Now Claude can:

  • Look up customer details (crm users get <id>)
  • List recent support tickets (crm tickets list --user-id <id>)
  • Send follow‑up emails (crm notifications send ...)

All from a single natural language request.

DevOps Automation

Wrap your infrastructure APIs (Kubernetes, cloud providers) in a CLI. Then ask Claude:

“Scale the web deployment to 5 replicas in staging, then check pod status.”

Claude runs kubectl scale deployment web --replicas=5 and kubectl get pods -l app=web (assuming you’ve generated CLIs for these). It’s like having an SRE assistant on demand.

Rapid API Testing

When developing a new API, generate a CLI immediately. Test endpoints manually, or have Claude run automated smoke tests and report results. The dual‑mode output makes it easy to switch between human inspection and scripted validation.

Legacy System Integration

Have an old internal API with outdated docs? Use peek‑api to capture traffic while using the web interface, then generate a modern CLI. Suddenly that legacy system becomes AI‑accessible.


Frequently Asked Questions

Does api2cli work with any API?

It’s optimized for RESTful JSON APIs. It can also handle some GraphQL APIs (especially when discovered via peek‑api). For SOAP or XML‑based APIs, you may need to customize the discovery patterns.

Do I need to maintain the generated CLI?

No. As long as your API doesn’t change, the CLI works forever. If the API evolves, you can rerun api2cli to generate an updated version. Because skills are separate, you can even keep multiple versions (v1, v2) side by side.

How are API keys handled securely?

The CLI reads credentials from environment variables (e.g., RESEND_API_KEY). This follows best practices and avoids hard‑coding secrets. The skill documentation clearly states which variables need to be set.

Is the generated code production‑ready?

Yes. The CLI includes error handling, retries, rate limiting, and caching—features essential for reliable production use. However, for critical applications, we recommend reviewing the generated code and adding any additional safeguards your use case requires.

How does Claude recognize and use the skill?

When Claude starts, it scans .claude/skills/ for SKILL.md files. It parses the YAML front matter to understand the skill’s purpose and triggers. During conversation, if the user’s request matches a trigger or the skill’s description, Claude loads it and can invoke the CLI commands as needed.


The Future of AI‑Tool Collaboration

api2cli is more than a code generator—it’s a glimpse into how we’ll interact with software in the age of AI. Instead of writing one‑off scripts or memorizing API documentation, we’ll build reusable, AI‑friendly tools that both humans and agents can use interchangeably.

Imagine a development environment where every microservice automatically exposes a CLI, and every CLI comes with a skill that teaches Claude how to use it. Onboarding new team members (human or AI) becomes trivial. Automating complex workflows becomes a conversation.

With projects like api2cli and peek‑api, that future is already taking shape. The next time you find yourself reading API docs and writing curl commands, consider whether a better way exists. Chances are, it does—and Claude is ready to help.


This article is based on the official api2cli documentation. For the latest updates, source code, and contribution guidelines, visit the GitHub repository.