Home/Models/OpenAI/GPT 5.1 Codex
O

GPT 5.1 Codex

Input:$1/M
Output:$8/M
Context:400K
Max Output:128K
GPT-5.1-Codex is a high-performance large language model focused on code generation and understanding, with enhanced capabilities for complex programming tasks, code reasoning, and production-level applications.
New
Commercial Use
Playground
Overview
Features
Pricing
API
Versions

What is the GPT-5.1-Codex ?

gpt-5.1-codex is a specialized member of OpenAI’s GPT-5.1 family, optimized for agentic, long-running software-engineering workflows (code generation, patching, large refactors, structured code review and multi-step agentic tasks).

Features

  • Agentic tooling first — built to emit structured patch operations and shell calls (the model can produce apply_patch_call and shell_call items which your integration executes and returns outputs for). This enables reliable create/update/delete operations across files.
  • Responses API only — Codex variants in the 5.1 line are available only via the Responses API and are tuned for tool-driven workflows rather than conversational chat flows.
  • Adaptive reasoning and latency modes — GPT-5.1 family introduces reasoning_effort (including a none mode for latency-sensitive interactions) and extended prompt caching (up to 24h) to improve interactive coding sessions. Codex models emphasize efficient iterative work.
  • Steerability and code personality — tuned to be more “deliberate” for fewer wasted actions in long sessions and to produce clearer update messages for PRs and patch diffs.
  • Codex-specific UX: IDE/CLI default model setting, session resume, context compaction, image/screenshot inputs for frontend tasks in Codex Web.

Technical details & operational considerations

  • API surface: gpt-5.1-codex is served via the Responses API (not Chat Completions). The Responses API supports tool calling, structured outputs, streaming, and the apply_patch and shell tools that Codex leverages.
  • Tool calling semantics: include tools in the request (tools: ). The model may emit apply_patch_call or shell_call items; your code executes the patch/command and returns outputs back to the model in the follow-up request. The Responses API is agentic by default so it can orchestrate multi-step plans.
  • Reasoning tuning: use reasoning={"effort":"none"} (Responses API) for minimal thinking/low latency, or {"effort":"medium"}/high for thorough code reasoning and validation. Note that none improves parallel tool-calling and latency-sensitive code edits.
  • Session persistence / context: Codex and the Responses API support session resume and context compaction to summarize older context as you approach the context limit, enabling extended interactive sessions without manual context trimming.

Primary use cases (recommended)

  • Interactive IDE workflows: intelligent code completion, PR drafting, inline patching and multi-turn code edits.
  • Agentic automation: long-running agent tasks that require applying a sequence of patches, running shell steps, and validating via tests.
  • Code review & refactoring: higher-quality diffs and structured review comments (SWE-bench improvements reported by partners).
  • Test generation & validation: generate unit/integration tests, run them via a controlled shell tool, iterate on failures.

How to use GPT-5.1 Codex API

Required Steps

  • Log in to cometapi.com. If you are not our user yet, please register first.
  • Sign into your CometAPI console.
  • Get the access credential API key of the interface. Click “Add Token” at the API token in the personal center, get the token key: sk-xxxxx and submit.

Use Method

  1. Select the “gpt-5.1-codex” endpoint to send the API request and set the request body. The request method and request body are obtained from our website API doc. Our website also provides Apifox test for your convenience.
  2. Replace <YOUR_API_KEY> with your actual CometAPI key from your account.
  3. Insert your question or request into the content field—this is what the model will respond to.
  4. . Process the API response to get the generated answer.

CometAPI provides a fully compatible REST API—for seamless migration. Key details to Responses

See also GPT-5.1 API and GPT-5.1-Chat-latest API

Features for GPT 5.1 Codex

Explore the key features of GPT 5.1 Codex, designed to enhance performance and usability. Discover how these capabilities can benefit your projects and improve user experience.

Pricing for GPT 5.1 Codex

Explore competitive pricing for GPT 5.1 Codex, designed to fit various budgets and usage needs. Our flexible plans ensure you only pay for what you use, making it easy to scale as your requirements grow. Discover how GPT 5.1 Codex can enhance your projects while keeping costs manageable.
Comet Price (USD / M Tokens)Official Price (USD / M Tokens)Discount
Input:$1/M
Output:$8/M
Input:$1.25/M
Output:$10/M
-20%

Sample code and API for GPT 5.1 Codex

gpt-5.1-codex is a specialized member of OpenAI’s GPT-5.1 family, optimized for agentic, long-running software-engineering workflows (code generation, patching, large refactors, structured code review and multi-step agentic tasks).
JavaScript
Curl
import OpenAI from "openai";

// Get your CometAPI key from https://api.cometapi.com/console/token, and paste it here
const api_key = process.env.COMETAPI_KEY;
const base_url = "https://api.cometapi.com/v1";

const openai = new OpenAI({
  apiKey: api_key,
  baseURL: base_url,
});

const response = await openai.responses.create({
  model: "gpt-5.1-codex",
  input: "Tell me a three sentence bedtime story about a unicorn.",
});

console.log(response);

Versions of GPT 5.1 Codex

The reason GPT 5.1 Codex has multiple snapshots may include potential factors such as variations in output after updates requiring older snapshots for consistency, providing developers a transition period for adaptation and migration, and different snapshots corresponding to global or regional endpoints to optimize user experience. For detailed differences between versions, please refer to the official documentation.
version
gpt-5.1-codex
gpt-5.1-codex-max

More Models