> For the complete documentation index, see [llms.txt](https://docs.cherryai.com.cn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cherryai.com.cn/docs/jp/advanced-basic/api-server.md).

# APIサーバー

APIサーバーの核心的な役割：**Cherry Studioで設定済みのAI機能を、ローカルインターフェースを通じて外部に公開する**（同時にエージェント機能の基盤依存でもあります）、他のプログラムから呼び出せるようにします。

使用シーン：Cherry StudioでOpenAI、Anthropic、DeepSeekなどのプロバイダーを設定済みです。もし他のツール（たとえばあるプラグインやカスタムスクリプト）が同じAI機能を呼び出したい場合、**API サーバー**このローカルで標準インターフェースを公開し、これらのツールがCherry Studioの既存設定を直接再利用できるようにします。各社アカウントを重複登録する必要はありません。

**いつ有効化する必要がありますか？**

* 使用する [エージェント](/docs/jp/cherry-studio/preview/agent.md) をクリック → **有効化が必要**
* AgentをIMプラットフォームに接続する（[チャンネル](/docs/jp/advanced-basic/agent-channels.md)）→ **有効化が必要**
* Cherry Studioの通常の対話、描画、翻訳などの機能のみを使用する → **有効化不要**

> まずはこちらを読むことをおすすめします [概念入門](/docs/jp/advanced-basic/concepts-101.md) Agent、チャネルなどの関連概念を理解します。

### APIサーバーを有効化

1. 開く `設定 → API サーバー`
2. デフォルトのリッスンポートは **23333**で、 **1000-65535** の間の任意の空きポートを入力できます
3. 右上の緑の **▶ 起動** ボタン

<figure><img src="/files/16c7e6183b5778ca9bde28154125b75ae559bf49" alt=""><figcaption><p>有効化されていない場合は「停止済み」と表示され、「エージェント機能を使用するにはAPIサーバーを有効化してください」と案内されます</p></figcaption></figure>

起動成功後、状態は緑に変わり **実行中**、リッスンアドレスが表示されます `http://127.0.0.1:<port>`に由来する：

<figure><img src="/files/1c9ed8447b69d5756444ea5012ddad584d236db6" alt=""><figcaption><p>実行中の状態で、「再起動」と「停止」ボタンが含まれます</p></figcaption></figure>

{% hint style="info" %}
**ポートを変更する方法**：ポート入力欄はサーバー実行中は読み取り専用です。変更したい場合は、先に ⏹ をクリックして **停止**し、ポートを変更してから再起動してください。
{% endhint %}

### APIキーと認証ヘッダー

**API キー**のような形で `cs-sk-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`、APIサーバーを初めて有効化したときに自動生成され、**継続して保持**され、サーバーを再起動しても更新されません。

手動で更新したい場合：**まず ⏹ をクリックしてサーバーを停止する必要があります**。そうすると、キーの右側に **再生成** ボタンが表示されます（実行中はコピー按钮のみ表示）。クリックすると旧キーは直ちに無効になり、再起動時に新しいキーが生成されます。

APIを呼び出す際は、リクエストヘッダーに次を追加する必要があります：

```
Authorization: Bearer cs-sk-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
```

{% hint style="warning" %}
APIキーには、あなたのCherry Studio内のすべてのProviderへのアクセス権があります。**公開ネットワークやチーム共有チャネルで露出させないでください**。
{% endhint %}

### APIドキュメントを見る

ページ右上の **APIドキュメント** ボタンをクリックすると、組み込みのOpenAPIインターフェースドキュメント（Swagger風）を開けます。完全なエンドポイントとリクエスト例が含まれます。

### ポート競合の確認

起動に失敗し、 `EADDRINUSE: address already in use 127.0.0.1:<port>` と表示される場合：

1. 別のCherry Studioインスタンスが同じポートを使用している可能性が高いです
2. ⏹ をクリックして停止し、ポートを別の空き値に変更してから再起動してください
3. またはターミナルで `lsof -i :<port>`（macOS / Linux）を実行して使用中プロセスを特定し、対処してください

### 再起動と停止

* **再起動**：↻ アイコンをクリックします。キー再生成後にすべての接続を強制的に更新する際によく使います
* **停止**：赤い ⏹ アイコンをクリックすると、サービスは直ちに閉じられます。使用中の [エージェント](/docs/jp/cherry-studio/preview/agent.md) と [チャンネル](/docs/jp/advanced-basic/agent-channels.md) への接続も同時に切断されます

{% hint style="info" %}
APIサーバーは `127.0.0.1`、**表示されません**のみをリッスンし、ローカルネットワークや公開ネットワークには公開されません。別マシンからアクセスする必要がある場合は、SSHリバーストンネルなどの類似手段を併用してください。
{% endhint %}

### 次のステップ

* 有効化後、そのまま設定を続けられます [エージェント](/docs/jp/cherry-studio/preview/agent.md)
* AgentをFeishu / Telegram / DiscordなどのIMプラットフォームに接続したい場合は、 [チャンネル](/docs/jp/advanced-basic/agent-channels.md)

***

### 💡 ヘルプの取得とフィードバックの送信

設定や使用の過程で疑問、Bug、機能改善の提案がある場合は、 [フィードバックと提案](/docs/jp/question-contact/suggestions.md) に記載の公式チャネルをご参照ください。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.cherryai.com.cn/docs/jp/advanced-basic/api-server.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
