SPB Git

Repository Public

code-generation.md 6.7 KB 205 lines markdown

1# Code generation23> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.45Writing, reviewing, editing, and answering questions about code is one of the primary use cases for OpenAI models today. This guide walks through your options for code generation with [`gpt-6-astra`](https://developers.openai.com/api/docs/models/gpt-6-astra) and Codex.67## Get started891011  - **[Use Codex for out-of-the-box coding agents](#use-codex)**: Connect your codebase to Codex and accelerate your projects using software engineering agents.12- **[Integrate with coding models](#integrate-with-coding-models)**: Use OpenAI models in your application. Add them to a model picker, for instance.13141516## Use Codex1718[**Codex**](https://developers.openai.com/codex) is OpenAI's coding agent for software development. It helps you write, review and debug code. Interact with Codex in a variety of interfaces: in your IDE, through the CLI, on web and mobile sites, or in your CI/CD pipelines with the SDK. Codex is the best way to get agentic software engineering on your projects.1920Codex works best with the latest general-purpose models, such as [`gpt-5.6`](https://developers.openai.com/api/docs/models/gpt-5.6-sol). We offer a range of models specifically designed to work with coding agents like Codex, such as [`gpt-5.3-codex`](https://developers.openai.com/api/docs/models/gpt-5.3-codex), but we recommend using the latest general-purpose model for most code generation tasks.2122See the [ChatGPT docs](https://developers.openai.com/codex) for setup guides, reference material, pricing, and more information.2324## Integrate with coding models2526For most API-based code generation, start with **`gpt-6-astra`**. It handles both general-purpose work and coding, which makes it a strong default when your application needs to write code, reason about requirements, inspect docs, and handle broader workflows in one place.2728This example shows how you can use the [Responses API](https://developers.openai.com/api/reference/resources/responses) for a code generation use case:2930Default model for most coding tasks3132```javascript33import OpenAI from "openai";34const openai = new OpenAI();3536const result = await openai.responses.create({37  model: "gpt-6-astra",38  input: `Find the null pointer exception in this code:3940def display_name(user):41    return user.profile.name4243print(display_name(None))44`,45  reasoning: { effort: "high" },46});4748console.log(result.output_text);49```5051```python52from openai import OpenAI5354client = OpenAI()5556result = client.responses.create(57    model="gpt-6-astra",58    input="""Find the null pointer exception in this code:5960def display_name(user):61    return user.profile.name6263print(display_name(None))64""",65    reasoning={"effort": "high"},66)6768print(result.output_text)69```7071```go72package main7374import (75	"context"76	"fmt"7778	"github.com/openai/openai-go/v3"79	"github.com/openai/openai-go/v3/responses"80	"github.com/openai/openai-go/v3/shared"81)8283func main() {84	client := openai.NewClient()85	response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{86		Model: "gpt-6-astra",87		Input: responses.ResponseNewParamsInputUnion{OfString: openai.String(`Find the null pointer exception in this code:8889def display_name(user):90    return user.profile.name9192print(display_name(None))`)},93		Reasoning: shared.ReasoningParam{Effort: shared.ReasoningEffortHigh},94	})95	if err != nil {96		panic(err)97	}98	fmt.Println(response.OutputText())99}100```101102```java103import com.openai.client.OpenAIClient;104import com.openai.client.okhttp.OpenAIOkHttpClient;105import com.openai.models.Reasoning;106import com.openai.models.ReasoningEffort;107import com.openai.models.responses.ResponseCreateParams;108109String code =110    """111    def display_name(user):112        return user.profile.name113114    print(display_name(None))115    """;116117ResponseCreateParams params =118    ResponseCreateParams.builder()119        .model("gpt-6-astra")120        .input("Find the null pointer exception in this code:\n\n" + code)121        .reasoning(Reasoning.builder().effort(ReasoningEffort.HIGH).build())122        .build();123124client.responses().create(params).output().stream()125    .flatMap(item -> item.message().stream())126    .flatMap(message -> message.content().stream())127    .flatMap(content -> content.outputText().stream())128    .forEach(text -> System.out.println(text.text()));129```130131```csharp132using OpenAI.Responses;133#pragma warning disable OPENAI001134135string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;136ResponsesClient client = new(key);137138CreateResponseOptions options = new()139{140    Model = "gpt-6-astra",141    ReasoningOptions = new ResponseReasoningOptions142    {143        ReasoningEffortLevel = ResponseReasoningEffortLevel.High,144    },145};146options.InputItems.Add(147    ResponseItem.CreateUserMessageItem(148        """149        Find the null pointer exception in this code:150151        def display_name(user):152            return user.profile.name153154        print(display_name(None))155        """156    )157);158159ResponseResult response = await client.CreateResponseAsync(options);160Console.WriteLine(response.GetOutputText());161```162163```ruby164require "openai"165166client = OpenAI::Client.new167code = <<~PYTHON168  def display_name(user):169      return user.profile.name170171  print(display_name(None))172PYTHON173174response = client.responses.create(175  model: "gpt-6-astra",176  input: "Find the null pointer exception in this code:\n\n#{code}",177  reasoning: { effort: :high }178)179180puts(response.output_text)181```182183```bash184curl https://api.openai.com/v1/responses \185  -H "Content-Type: application/json" \186  -H "Authorization: Bearer $OPENAI_API_KEY" \187  -d '{188    "model": "gpt-6-astra",189    "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",190    "reasoning": { "effort": "high" }191  }'192```193194195## Frontend development196197Our models from the GPT-5 family are especially strong at frontend development, especially when combined with a coding agent harness such as Codex.198199The demo applications below were one shot generations, i.e. generated from a single prompt without hand-written code. Use them to evaluate frontend generation quality and prompt patterns for UI-heavy code generation workflows.200201## Next steps202203- Visit the [ChatGPT docs](https://developers.openai.com/codex) to learn what you can do with Codex, set up Codex in whichever interface you choose, or find more details.204- Read [Model guidance](https://developers.openai.com/api/docs/guides/latest-model) for model selection, features, migration guidance, and prompting patterns that work well on coding and agentic tasks.205- Compare [`gpt-6-astra`](https://developers.openai.com/api/docs/models/gpt-6-astra) and [`gpt-5.3-codex`](https://developers.openai.com/api/docs/models/gpt-5.3-codex) on the model pages.
Files main
Menu

Theme