コードの作成、レビュー、編集、コードに関する質問への回答は、現在の OpenAI モデルの主要なユースケースの一つです。このガイドでは、gpt-6-astra と Codex によるコード生成の選択肢を紹介します。
Codex は、ソフトウェア開発向けの OpenAI のコーディングエージェントです。コードの作成、レビュー、デバッグを支援します。IDE、CLI、ウェブサイトやモバイルサイト、SDK を使った CI/CD パイプラインなど、さまざまなインターフェースから利用できます。プロジェクトにエージェントによるソフトウェアエンジニアリングを導入するには、Codex が最適です。
Codex は、gpt-5.6 などの最新の汎用モデルと組み合わせることで、最も優れた性能を発揮します。gpt-5.3-codex など、Codex のようなコーディングエージェント向けに設計されたモデルも各種提供していますが、ほとんどのコード生成タスクには最新の汎用モデルを推奨します。
セットアップガイド、リファレンス資料、料金などの詳細については、ChatGPT のドキュメントをご覧ください。
API を使ったコード生成では、ほとんどの場合、まず gpt-6-astra をお試しください。汎用的な作業とコーディングの両方に対応しているため、コードの作成、要件についての推論、ドキュメントの確認に加え、より幅広いワークフローを一つのアプリケーションで扱う場合に、標準の選択肢として適しています。
次の例は、コード生成のユースケースで Responses API を使用する方法を示しています。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16import OpenAI from "openai";
const openai = new OpenAI();
const result = await openai.responses.create({
model: "gpt-6-astra",
input: `Find the null pointer exception in this code:
def display_name(user):
return user.profile.name
print(display_name(None))
`,
reasoning: { effort: "high" },
});
console.log(result.output_text);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17from openai import OpenAI
client = OpenAI()
result = client.responses.create(
model="gpt-6-astra",
input="""Find the null pointer exception in this code:
def display_name(user):
return user.profile.name
print(display_name(None))
""",
reasoning={"effort": "high"},
)
print(result.output_text)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
"github.com/openai/openai-go/v3/shared"
)
func main() {
client := openai.NewClient()
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String(`Find the null pointer exception in this code:
def display_name(user):
return user.profile.name
print(display_name(None))`)},
Reasoning: shared.ReasoningParam{Effort: shared.ReasoningEffortHigh},
})
if err != nil {
panic(err)
}
fmt.Println(response.OutputText())
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.Reasoning;
import com.openai.models.ReasoningEffort;
import com.openai.models.responses.ResponseCreateParams;
String code =
"""
def display_name(user):
return user.profile.name
print(display_name(None))
""";
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input("Find the null pointer exception in this code:\n\n" + code)
.reasoning(Reasoning.builder().effort(ReasoningEffort.HIGH).build())
.build();
client.responses().create(params).output().stream()
.flatMap(item -> item.message().stream())
.flatMap(message -> message.content().stream())
.flatMap(content -> content.outputText().stream())
.forEach(text -> System.out.println(text.text()));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29using OpenAI.Responses;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
ResponsesClient client = new(key);
CreateResponseOptions options = new()
{
Model = "gpt-6-astra",
ReasoningOptions = new ResponseReasoningOptions
{
ReasoningEffortLevel = ResponseReasoningEffortLevel.High,
},
};
options.InputItems.Add(
ResponseItem.CreateUserMessageItem(
"""
Find the null pointer exception in this code:
def display_name(user):
return user.profile.name
print(display_name(None))
"""
)
);
ResponseResult response = await client.CreateResponseAsync(options);
Console.WriteLine(response.GetOutputText());
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17require "openai"
client = OpenAI::Client.new
code = <<~PYTHON
def display_name(user):
return user.profile.name
print(display_name(None))
PYTHON
response = client.responses.create(
model: "gpt-6-astra",
input: "Find the null pointer exception in this code:\n\n#{code}",
reasoning: { effort: :high }
)
puts(response.output_text)
1
2
3
4
5
6
7
8curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-6-astra",
"input": "Find the null pointer exception in this code:\n\ndef display_name(user):\n return user.profile.name\n\nprint(display_name(None))\n",
"reasoning": { "effort": "high" }
}'
GPT-5 ファミリーのモデルはフロントエンド開発を特に得意としており、Codex のようなコーディングエージェントのハーネスと組み合わせると、その強みをさらに発揮します。
以下のデモアプリケーションは、コードを手書きせず、単一のプロンプトからワンショットで生成したものです。UI を中心としたコード生成ワークフローにおける、フロントエンドの生成品質やプロンプトのパターンの評価にご活用ください。