AI Agent Hub
AI エージェント / プラグイン情報メディア
← 一覧へ
agentapi
CLAUDE

agentapi

agentapi

Claude Code / Codex / Aider / Goose を共通 HTTP API として扱えるラッパー。Web UI からエージェントを操作するアプリやエンタープライズ統合を構築できる。

原文: HTTP API for Claude Code, Goose, Aider, Gemini, Amp, and Codex
#HTTP API#ラッパー#Coder
REPO STATS

リポジトリ統計

⭐ Stars
1.4k
🍴 Forks
119
⚠️ Open Issues
37
🌿 Language
Go
📄 License
MIT
🕒 最終更新
2026.04.14 (3週間前)
📅 公開日
2025.04.07
🌿 Branch
main
README

ドキュメント

— AI による自動翻訳 (2026.05.07 更新)

AgentAPI

Claude Code、AmazonQOpencodeGooseAiderGeminiGitHub CopilotSourcegraph AmpCodexAuggie、およびCursor CLI を HTTP API で制御します。

agentapi-chat

AgentAPI は以下のような用途で使用できます:

  • コーディングエージェント向けの統一されたチャットインターフェースを構築する
  • 1 つのエージェントが別のコーディングエージェントを制御できるようにする MCP サーバーのバックエンドとして使用する
  • プルリクエストレビューをエージェントに送信するツールを作成する
  • その他にも多くの使い方があります!

クイックスタート

  1. agentapi をインストールしてください:

    OS=$(uname -s | tr "[:upper:]" "[:lower:]");
    ARCH=$(uname -m | sed "s/x86_64/amd64/;s/aarch64/arm64/");
    curl -fsSL "https://github.com/coder/agentapi/releases/latest/download/agentapi-${OS}-${ARCH}" -o agentapi && chmod +x agentapi

    または、最新のリリースバイナリをリリースページからダウンロードすることもできます。

  2. インストールを確認してください:

    agentapi --help

    macOS では、システムがバイナリを検証できないというメッセージが表示された場合は、System Settings → Privacy & Security に移動し、「Open Anyway」をクリックしてからコマンドを再度実行してください。

  3. Claude Code サーバーを実行してください(システムに claude がインストールされており、PATH に含まれていることを前提としています):

    agentapi server -- claude

    claudePATH にないというエラーが表示されても、シェルから実行できる場合は、which claude を使用して完全なパスを取得し、代わりにそのパスを使用してください。

  4. エージェントにメッセージを送信してください:

    curl -X POST localhost:3284/message \
      -H "Content-Type: application/json" \
      -d '{"content": "Hello, agent!", "type": "user"}'
  5. 会話履歴を取得してください:

    curl localhost:3284/messages
  6. http://localhost:3284/chat でチャット Web インターフェースを試してください。

CLI コマンド

agentapi server

エージェントを制御できる HTTP サーバーを実行します。エージェントに追加の引数を渡したい場合は、-- フラグの後に完全なエージェントコマンドを渡してください。

agentapi server -- claude --allowedTools "Bash(git*) Edit Replace"

agentapi を使用して Aider および Goose エージェントを実行することもできます:

agentapi server -- aider --model sonnet --api-key anthropic=sk-ant-apio3-XXX
agentapi server -- goose

Claude、Codex、Opencode、Copilot、Gemini、Amp または CursorCLI を使用する場合は、常にエージェントタイプを明示的に指定してください(例:agentapi server --type=codex -- codex)。指定しないと、メッセージのフォーマットが崩れる可能性があります。

OpenAPI スキーマは openapi.json で利用できます。

デフォルトでは、サーバーはポート 3284 で実行されます。さらに、サーバーは同じ OpenAPI スキーマを http://localhost:3284/openapi.json で公開し、利用可能なエンドポイントをドキュメンテーション UI で http://localhost:3284/docs で公開します。

4 つのエンドポイントがあります:

  • GET /messages - エージェントとの会話内のすべてのメッセージのリストを返します
  • POST /message - エージェントにメッセージを送信します。200 応答が返された場合、AgentAPI はエージェントがメッセージの処理を開始したことを検出しています
  • GET /status - エージェントの現在のステータスを返します。「stable」または「running」のいずれかです
  • GET /events - エージェントからのイベントの SSE ストリーム:メッセージとステータスの更新

許可されたホスト

デフォルトでは、サーバーはホストヘッダーが localhost に設定されたリクエストのみを許可します。AgentAPI を他の場所でホストしたい場合は、AGENTAPI_ALLOWED_HOSTS 環境変数または --allowed-hosts フラグを使用して変更できます。ホストはホスト名のみである必要があります(ポートなし)。サーバーは認可時に受け取ったリクエストのポート部分を無視します。

任意のホストからのリクエストを許可するには、許可されたホストとして * を使用します。

agentapi server --allowed-hosts '*' -- claude

特定のホストを許可するには、次を使用します:

agentapi server --allowed-hosts 'example.com' -- claude

複数のホストを指定するには、--allowed-hosts フラグを使用するときはカンマで区切られたリストを、AGENTAPI_ALLOWED_HOSTS 環境変数を使用するときはスペースで区切られたリストを使用します。

agentapi server --allowed-hosts 'example.com,example.org' -- claude
# or
AGENTAPI_ALLOWED_HOSTS='example.com example.org' agentapi server -- claude

許可されたオリジン

デフォルトでは、サーバーは http://localhost:3284http://localhost:3000、および http://localhost:3001 からの CORS リクエストを許可します。AgentAPI へのクロスオリジンリクエストを行うことができるオリジンを変更する場合は、AGENTAPI_ALLOWED_ORIGINS 環境変数または --allowed-origins フラグを使用して変更できます。

任意のオリジンからのリクエストを許可するには、許可されたオリジンとして * を使用します:

agentapi server --allowed-origins '*' -- claude

特定のオリジンを許可するには、次を使用します:

agentapi server --allowed-origins 'https://example.com' -- claude

複数のオリジンを指定するには、--allowed-origins フラグを使用するときはカンマで区切られたリストを、AGENTAPI_ALLOWED_ORIGINS 環境変数を使用するときはスペースで区切られたリストを使用します。オリジンはプロトコル(http:// または https://)を含む必要があり、ワイルドカード(例:https://*.example.com)をサポートします:

agentapi server --allowed-origins 'https://example.com,http://localhost:3000' -- claude
# or
AGENTAPI_ALLOWED_ORIGINS='https://example.com http://localhost:3000' agentapi server -- claude

agentapi attach

実行中のエージェントのターミナルセッションにアタッチします。

agentapi attach --url localhost:3284

ctrl+c を押してセッションからデタッチします。

動作方法

AgentAPI はメモリ内ターミナルエミュレータを実行します。API呼び出しを適切なターミナルキーストロークに変換し、エージェントの出力を個別のメッセージに解析します。

ターミナル出力をメッセージに分割

メッセージには 2 つのタイプがあります:

  • ユーザーメッセージ:ユーザーからエージェントに送信されるメッセージ
  • エージェントメッセージ:エージェントからユーザーに送信されるメッセージ

ターミナル出力から個別のメッセージを解析するために、以下の手順を実行します:

  1. ユーザーメッセージが送信される前の初期ターミナル出力は、エージェントの最初のメッセージとして扱われます。
  2. ユーザーが API 経由でメッセージを送信すると、キーストロークが送信される前にターミナルのスナップショットが取得されます。
  3. ユーザーメッセージがエージェントに送信されます。この時点から、ターミナル出力が変更されるたびに新しいスナップショットが取得されます。初期スナップショットと比較され、初期コンテンツの下に表示される新しいテキストがエージェントの次のメッセージとして扱われます。
  4. 新しいユーザーメッセージが送信される前にターミナル出力が再度変更された場合、エージェントメッセージが更新されます。

これにより、ターミナル出力をメッセージのシーケンスに分割できます。

エージェントメッセージから TUI 要素を削除

各エージェントメッセージには、エンドユーザーにとって有用でない余分な部分が含まれています:

  • メッセージの開始時のユーザー入力。コーディングエージェントは、入力をターミナルで見やすくするために、ユーザーに入力をエコーバックすることがよくあります。
  • メッセージの最後にある入力ボックス。これはユーザーが通常入力を入力する場所です。

AgentAPI は自動的にこれらを削除します。

  • ユーザー入力については、ユーザーの最後のメッセージからのテキストを含む行を削除します。
  • 入力ボックスについては、メッセージの最後にある、一般的な TUI 要素を含む行を探します。例えば > または ------ のような行です。

Claude Code、Goose、Aider、または Codex が TUI を更新したらどうなりますか?

ターミナル出力をメッセージのシーケンスに分割することは、TUI 構造に依存しないため、引き続き機能するはずです。余分なビットを削除するロジックは、新しい要素に対応するために更新が必要になる場合があります。AgentAPI は引き続き使用できますが、エージェントメッセージに一部の余分な TUI 要素が表示される可能性があります。

ロードマップ

フィードバック待機中、以下の機能を検討しています:

長期的なビジョン

短期的には、AgentAPI はコーディングエージェントをプログラムで制御する方法の問題を解決します。時間が経つにつれて、主要なエージェントが適切な SDK をリリースすることを期待しています。その時点で AgentAPI がまだ必要かどうか疑問に思う人がいるかもしれません。これはエージェントベンダーが共通の API に標準化することを決定するか、または各自が独自の形式に固執するかによって異なると思います。

前者の場合、公式 SDK に優先して AgentAPI は廃止されます。後者の場合、AgentAPI を任意のコーディングエージェントを制御するユニバーサルアダプターにすることが目標になります。これにより、AgentAPI を使用する開発者がコードを変更せずにエージェント間を切り替えることができます。

— GitHub から取得した原文(一部省略の場合あり)

AgentAPI

Control Claude Code, AmazonQ, Opencode, Goose, Aider, Gemini, GitHub Copilot, Sourcegraph Amp, Codex, Auggie, and Cursor CLI with an HTTP API.

agentapi-chat

You can use AgentAPI:

  • to build a unified chat interface for coding agents
  • as a backend in an MCP server that lets one agent control another coding agent
  • to create a tool that submits pull request reviews to an agent
  • and much more!

Quickstart

  1. Install agentapi:

    OS=$(uname -s | tr "[:upper:]" "[:lower:]");
    ARCH=$(uname -m | sed "s/x86_64/amd64/;s/aarch64/arm64/");
    curl -fsSL "https://github.com/coder/agentapi/releases/latest/download/agentapi-${OS}-${ARCH}" -o agentapi && chmod +x agentapi

    Alternatively, you can download the latest release binary from the releases page.

  2. Verify the installation:

    agentapi --help

    On macOS, if you're prompted that the system was unable to verify the binary, go to System Settings -> Privacy & Security, click "Open Anyway", and run the command again.

  3. Run a Claude Code server (assumes claude is installed on your system and in the PATH):

    agentapi server -- claude

    If you're getting an error that claude is not in the PATH but you can run it from your shell, try which claude to get the full path and use that instead.

  4. Send a message to the agent:

    curl -X POST localhost:3284/message \
      -H "Content-Type: application/json" \
      -d '{"content": "Hello, agent!", "type": "user"}'
  5. Get the conversation history:

    curl localhost:3284/messages
  6. Try the chat web interface at http://localhost:3284/chat.

CLI Commands

agentapi server

Run an HTTP server that lets you control an agent. If you'd like to start an agent with additional arguments, pass the full agent command after the -- flag.

agentapi server -- claude --allowedTools "Bash(git*) Edit Replace"

You may also use agentapi to run the Aider and Goose agents:

agentapi server -- aider --model sonnet --api-key anthropic=sk-ant-apio3-XXX
agentapi server -- goose

Note

When using Claude, Codex, Opencode, Copilot, Gemini, Amp or CursorCLI, always specify the agent type explicitly (eg: agentapi server --type=codex -- codex), or message formatting may break.

An OpenAPI schema is available in openapi.json.

By default, the server runs on port 3284. Additionally, the server exposes the same OpenAPI schema at http://localhost:3284/openapi.json and the available endpoints in a documentation UI at http://localhost:3284/docs.

There are 4 endpoints:

  • GET /messages - returns a list of all messages in the conversation with the agent
  • POST /message - sends a message to the agent. When a 200 response is returned, AgentAPI has detected that the agent started processing the message
  • GET /status - returns the current status of the agent, either "stable" or "running"
  • GET /events - an SSE stream of events from the agent: message and status updates

Allowed hosts

By default, the server only allows requests with the host header set to localhost. If you'd like to host AgentAPI elsewhere, you can change this by using the AGENTAPI_ALLOWED_HOSTS environment variable or the --allowed-hosts flag. Hosts must be hostnames only (no ports); the server ignores the port portion of incoming requests when authorizing.

To allow requests from any host, use * as the allowed host.

agentapi server --allowed-hosts '*' -- claude

To allow a specific host, use:

agentapi server --allowed-hosts 'example.com' -- claude

To specify multiple hosts, use a comma-separated list when using the --allowed-hosts flag, or a space-separated list when using the AGENTAPI_ALLOWED_HOSTS environment variable.

agentapi server --allowed-hosts 'example.com,example.org' -- claude
# or
AGENTAPI_ALLOWED_HOSTS='example.com example.org' agentapi server -- claude

Allowed origins

By default, the server allows CORS requests from http://localhost:3284, http://localhost:3000, and http://localhost:3001. If you'd like to change which origins can make cross-origin requests to AgentAPI, you can change this by using the AGENTAPI_ALLOWED_ORIGINS environment variable or the --allowed-origins flag.

To allow requests from any origin, use * as the allowed origin:

agentapi server --allowed-origins '*' -- claude

To allow a specific origin, use:

agentapi server --allowed-origins 'https://example.com' -- claude

To specify multiple origins, use a comma-separated list when using the --allowed-origins flag, or a space-separated list when using the AGENTAPI_ALLOWED_ORIGINS environment variable. Origins must include the protocol (http:// or https://) and support wildcards (e.g., https://*.example.com):

agentapi server --allowed-origins 'https://example.com,http://localhost:3000' -- claude
# or
AGENTAPI_ALLOWED_ORIGINS='https://example.com http://localhost:3000' agentapi server -- claude

agentapi attach

Attach to a running agent's terminal session.

agentapi attach --url localhost:3284

Press ctrl+c to detach from the session.

How it works

AgentAPI runs an in-memory terminal emulator. It translates API calls into appropriate terminal keystrokes and parses the agent's outputs into individual messages.

Splitting terminal output into messages

There are 2 types of messages:

  • User messages: sent by the user to the agent
  • Agent messages: sent by the agent to the user

To parse individual messages from the terminal output, we take the following steps:

  1. The initial terminal output, before any user messages are sent, is treated as the agent's first message.
  2. When the user sends a message through the API, a snapshot of the terminal is taken before any keystrokes are sent.
  3. The user message is then submitted to the agent. From this point on, any time the terminal output changes, a new snapshot is taken. It's diffed against the initial snapshot, and any new text that appears below the initial content is treated as the agent's next message.
  4. If the terminal output changes again before a new user message is sent, the agent message is updated.

This lets us split the terminal output into a sequence of messages.

Removing TUI elements from agent messages

Each agent message contains some extra bits that aren't useful to the end user:

  • The user's input at the beginning of the message. Coding agents often echo the input back to the user to make it visible in the terminal.
  • An input box at the end of the message. This is where the user usually types their input.

AgentAPI automatically removes these.

  • For user input, we strip the lines that contain the text from the user's last message.
  • For the input box, we look for lines at the end of the message that contain common TUI elements, like > or ------.

What will happen when Claude Code, Goose, Aider, or Codex update their TUI?

Splitting the terminal output into a sequence of messages should still work, since it doesn't depend on the TUI structure. The logic for removing extra bits may need to be updated to account for new elements. AgentAPI will still be usable, but some extra TUI elements may become visible in the agent messages.

Roadmap

Pending feedback, we're considering the following features:

Long-term vision

In the short term, AgentAPI solves the problem of how to programmatically control coding agents. As time passes, we hope to see the major agents release proper SDKs. One might wonder whether AgentAPI will still be needed then. We think that depends on whether agent vendors decide to standardize on a common API, or each sticks with a proprietary format.

In the former case, we'll deprecate AgentAPI in favor of the official SDKs. In the latter case, our goal will be to make AgentAPI a universal adapter to control any coding agent, so a developer using AgentAPI can switch between agents without changing their code.

RELATED

同じカテゴリの他のツール