> 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](#web-search-and-thinking)、ツール呼び出し、 [コード実行](#code-execution), [画像生成](#image-generation)、再利用可能なコードコンテナ、そして [プロンプトキャッシュ](#prompt-caching).

ChatGPT/Codexのサブスクリプションも、直接Unslothに接続できます。

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

### セットアップ

{% stepper %}
{% step %}

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

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

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FNbLWLZa1OBYQrwX0mQVv%2Funsloth_openai_api.gif?alt=media&amp;token=28187d50-8638-4e60-ba33-729efd13f1c1" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### 接続を設定

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

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

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FlAXYV1wS2lxeS36Lo8Dj%2Fexport-1779457818713.gif?alt=media&amp;token=99c6f0b2-2fb1-40e4-a15a-325bcef8c2f7" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

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

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

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FgKCJ3zsZzZuDqBAigsfG%2FScreenshot%202026-05-26%20at%201.31.03%E2%80%AFAM.png?alt=media&amp;token=c8df4285-ba69-4091-8978-e4197f6a12d2" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### コード実行

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

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fn65DzRsTGrflcqJBv67y%2FScreenshot%202026-05-26%20at%206.11.54%E2%80%AFAM.png?alt=media&amp;token=f620e467-2202-4843-ae16-e169a89f0a57" alt="" width="563"><figcaption></figcaption></figure>

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

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

{% column width="50%" %}

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FBR0zCMzeC4IwPSmlx12A%2Fimage.png?alt=media&amp;token=3d9e80ee-4ceb-4454-9620-165650a29c0a" alt="" width="288"><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

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

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

{% column width="33.33333333333334%" %}

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FKA6iU3qCFhUiq0KI16aU%2FScreenshot%202026-05-26%20at%203.28.44%E2%80%AFAM.png?alt=media&amp;token=41a43794-792d-48f4-8774-8b9d85702dfc" alt=""><figcaption></figcaption></figure>

{% endcolumn %}
{% endcolumns %}

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fq4csmTX5rS9isMkNkhTX%2FPrompt%20Caching%20Diagram%20(1).png?alt=media&amp;token=ade433bf-5eaf-4146-a266-525a85a6c98d" alt="" width="375"><figcaption></figcaption></figure>

### Web検索と思考

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

<div data-with-frame="true"><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FC0Ed4kzN9h6c0ogEn6NT%2Fwebsearch%20api.png?alt=media&amp;token=d3335222-1d9e-4021-9bf9-734c6acf1fc0" alt="" width="563"><figcaption></figcaption></figure></div>

### 画像生成

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

<div><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F5ZLU2BY19MN4yiYLx2Br%2FScreenshot%202026-05-26%20at%206.04.34%E2%80%AFAM.png?alt=media&amp;token=44327a8f-c14d-4541-9a02-f19f375b4326" alt=""><figcaption></figcaption></figure> <figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FDQ1bJ5KF8CiyItrfOrIt%2FScreenshot%202026-05-26%20at%206.06.07%E2%80%AFAM.png?alt=media&amp;token=ff6b00bc-0a2f-4375-a454-49429cf839f2" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://unsloth.ai/docs/jp/tong-he/connections/openai.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
