0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OpenAI の「Code Interpreter」が Responses API に対応したのでサクッと試す

Last updated at Posted at 2025-05-21

以下で発表された新機能の中の1つ「Code Interpreter の Responses API での利用」を試してみます。

●New tools and features in the Responses API | OpenAI
 https://openai.com/index/new-tools-and-features-in-the-responses-api/

image.png

サクッと試す

公式情報

「Code Interpreter の Responses API での利用」に関する公式ドキュメントは以下です。

●Code Interpreter - OpenAI API
 https://platform.openai.com/docs/guides/tools-code-interpreter#usage-notes

image.png

シンプルな使い方

一番シンプルな使い方は以下になるようです。

image.png

curl を使ったサンプルで、環境変数 OPENAI_API_KEY に APIキーを設定しておけば、以下のコマンドを実行するだけという感じです。

curl https://api.openai.com/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-4.1",
    "tools": [{
      "type": "code_interpreter",
      "container": { "type": "auto" }
    }],
    "instructions": "You are a personal math tutor. When asked a math question, write and run code to answer the question.",
    "input": "I need to solve the equation 3x + 11 = 14. Can you help me?"
  }'

実際に試す

上記のサンプルをそのまま実行してみます。以下は、その実行結果の抜粋です。

image.png

以下の部分で、計算結果が出ているのを確認できました。

image.png

【追記】 Node.js のサンプルが追加されたので試してみた

記事を公開後、Node.js(と Python)のサンプルが追加されたようなので、それも試してみました。

image.png

下準備

上記の curl の例と同じく、環境変数 OPENAI_API_KEY に APIキーを設定しておきます。

また、パッケージ「openai」をインストールしておきます。

npm i openai

試すコードと実行結果

試すコードは、公式サンプルそのままです。

import OpenAI from "openai";
const client = new OpenAI();

const resp = await client.responses.create({
  model: "gpt-4.1",
  tools: [
    {
      type: "code_interpreter",
      container: { type: "auto" },
    },
  ],
  instructions:
    "You are a personal math tutor. When asked a math question, write and run code to answer the question.",
  input: "I need to solve the equation 3x + 11 = 14. Can you help me?",
});

console.log(resp.output_text);

実行結果は以下のとおりで、curl で試した時と同じ結果が得られました。

image.png

余談

他に同時に発表された内容を、公式のブログ記事からキャプチャ画像ベースで列挙してみます。

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?