> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/jp/tong-he/connections/openai.md).

# OpenAIをUnslothに接続：ローカルチャットでGPTモデルを実行

GPT-5.5 を含む OpenAI モデルを接続する方法を学び、 [Unsloth](https://github.com/unslothai/unsloth) オープンソースのローカル UI チャットインターフェースでそれらすべてとチャットできるようにします。OpenAI API キーを接続すると、Unsloth 内で GPT モデルを次のような機能とともに実行できます。 [ウェブ検索](#web-search-and-thinking)、ツール呼び出し、 [コード実行](#code-execution), [画像生成](#image-generation)、再利用可能なコードコンテナ、そして [プロンプトキャッシュ](#prompt-caching).

このガイドでは、OpenAI API キーの作成、プロバイダーとしての OpenAI の接続、利用可能なモデルの読み込み、一般的なセットアップ問題のトラブルシューティングを順を追って説明します。

### セットアップ

{% stepper %}
{% step %}

#### OpenAI API キーを作成する

から API キーを作成します。 [OpenAI ダッシュボード](https://platform.openai.com/api-keys).

<figure><img src="/files/f0713397638f52638447250d116a856da95b1338" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### 接続を設定する

次に、プロバイダーを Unsloth に接続します。

1. 開く **設定** → **接続**、その後 **接続を追加。**
2. OpenAI を選択し、先ほどコピーした API キーを貼り付けます。
3. クリック **モデルを再読み込み** して、アカウントで利用可能なモデルの一覧を更新します。
4. 有効にしたいモデルを選択し、保存をクリックします。&#x20;

<figure><img src="/files/b5075d9bb54f6ebf6218fd655ea3aadd4e942081" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### チャット準備完了

有効にしたモデルは、これで「モデルを選択」ドロップダウンの「接続済み」の下に表示されます。対応している GPT モデルでは、画像生成、思考、ウェブ検索、コード実行などの追加コントロールを利用できます。

<figure><img src="/files/65e30336af1ddc159ab502cdbf8d12011abc4b99" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### コード実行

有効にすると、対応する OpenAI モデルはプロバイダーのサンドボックス内でコードを実行し、問題の解決、データ分析、ファイルの操作を行えます。

<figure><img src="/files/336c26c1212bc12deb22711541023aa227e5eb78" alt="" width="563"><figcaption></figcaption></figure>

{% columns %}
{% column width="50%" %}
OpenAI は再利用可能なシェルコンテナを使用します。 **コード実行** 設定では、アイドルタイムアウトの設定、コンテナの作成、アクティブなコンテナの選択、一覧の更新、古いコンテナの削除ができます。

新しいスレッドで同じコンテナを選択すると、そのファイルと状態を引き継いで続行できます。
{% endcolumn %}

{% column width="50%" %}

<figure><img src="/files/b6ab615e3e66ab21ca4524900b0a73402c5cda27" alt="" width="288"><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

### プロンプトキャッシュ

{% columns %}
{% column width="66.66666666666666%" %}
プロンプトキャッシュは、リクエストで同じ長いプレフィックスを再利用する場合のレイテンシーとコストを削減します。OpenAI を含む、互換性のあるプロバイダーとサーバーでサポートされています。サポートされている接続のキャッシュ動作を制御するには、サイドパネルの **プロンプトキャッシュ** 設定を使用してください。
{% endcolumn %}

{% column width="33.33333333333334%" %}

<figure><img src="/files/e482d692d1a77c68eb712a04952a92f16b3a7953" alt=""><figcaption></figcaption></figure>

{% endcolumn %}
{% endcolumns %}

<figure><img src="/files/5bcf6fff0534310d56b7bea1b8e416dab545b5b1" alt="" width="375"><figcaption></figcaption></figure>

### ウェブ検索と思考

プロバイダー側のウェブ検索は、OpenAI の対応モデルで利用できます。 **考える** コントロールは選択したモデルに応じて変化します。モデルによってはオン/オフのトグルを使用し、推論重視のモデルではモデル固有の思考レベルを使用します。&#x20;

<div data-with-frame="true"><figure><img src="/files/0dbb7389f8d19ef42407933ecd60c6ec7f8ab667" alt="" width="563"><figcaption></figcaption></figure></div>

### 画像生成

GPT と同様に、Unsloth も画像生成をサポートしています。「画像を編集」ボタンをクリックして新しいプロンプトを入力すれば、画像を直接編集して、調整または再生成できます。画像は要求されたときに自動的に生成されますが、この動作はオフに切り替えることもできます。ダウンロードボタンも用意されており、画像を元のフル解像度のまま保存できます。

<div><figure><img src="/files/608f1d427d7bb7f6bcba5b41e56c5f6f91b61e0f" alt=""><figcaption></figcaption></figure> <figure><img src="/files/d7ee45546a10e40d4cb4372b481998df41fbb90e" alt=""><figcaption></figcaption></figure></div>

### トラブルシューティング

OpenAI への接続に失敗する場合は、API キーが有効で、正しい OpenAI アカウントに属していることを確認してください。

モデルが表示されない場合は **モデルを読み込む**、そのモデルがアカウントで利用できない可能性があります。モデル ID を手動で入力するか、別のモデルを選択できます。


---

# 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://unsloth.ai/docs/jp/tong-he/connections/openai.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.
