Skip to content

Commit a715715

Browse files
bigyao25Reid
andauthored
feat(openai): add GPT-6.1 Terra support (#2379)
Add GPT-6.1 Terra to the native OpenAI and subscription-based Codex catalogs without changing provider defaults. Configure official context and output limits, provider-specific reasoning efforts, image input, prompt caching, Standard/Flex/Priority pricing, and long-context multipliers. Route Codex requests through Responses Lite. Add dedicated Terra request tests for reasoning selection, native tool requests, priority pricing, and Codex Fast-mode headers and tool shaping. Preserve the existing Sol test file unchanged. Co-authored-by: Reid <[email protected]>
1 parent 332d30f commit a715715

5 files changed

Lines changed: 251 additions & 1 deletion

File tree

‎packages/types/src/__tests__/openai-models.test.ts‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,71 @@ import { openAiCodexDefaultModelId, openAiCodexModels } from "../providers/opena
22
import { openAiNativeDefaultModelId, openAiNativeModels } from "../providers/openai.js"
33

44
describe("OpenAI native models", () => {
5+
it("describes GPT-6.1 Terra pricing and optional native reasoning without changing defaults", () => {
6+
expect(openAiNativeDefaultModelId).toBe("gpt-5.6-sol")
7+
expect(openAiCodexDefaultModelId).toBe("gpt-5.6-sol")
8+
const model = openAiNativeModels["gpt-6.1-terra"]
9+
expect(model).toMatchObject({
10+
maxTokens: 128_000,
11+
contextWindow: 1_050_000,
12+
includedTools: ["apply_patch"],
13+
excludedTools: ["apply_diff", "write_to_file"],
14+
supportsImages: true,
15+
supportsPromptCache: true,
16+
supportsReasoningEffort: ["none", "low", "medium", "high", "xhigh", "max"],
17+
reasoningEffort: "medium",
18+
supportsTemperature: false,
19+
supportsVerbosity: true,
20+
inputPrice: 1,
21+
outputPrice: 5,
22+
cacheWritesPrice: 1.25,
23+
cacheWritesPrice12h: 2.5,
24+
cacheReadsPrice: 0.05,
25+
longContextPricing: {
26+
thresholdTokens: 272_000,
27+
inputPriceMultiplier: 2,
28+
outputPriceMultiplier: 1.5,
29+
cacheWritesPriceMultiplier: 2,
30+
cacheReadsPriceMultiplier: 2,
31+
appliesToServiceTiers: ["default", "flex", "priority"],
32+
},
33+
})
34+
expect(model).not.toHaveProperty("requiredReasoningEffort", true)
35+
expect(model.tiers).toEqual([
36+
{
37+
name: "flex",
38+
contextWindow: 1_050_000,
39+
inputPrice: 0.5,
40+
outputPrice: 2.5,
41+
cacheWritesPrice: 0.625,
42+
cacheReadsPrice: 0.025,
43+
},
44+
{
45+
name: "priority",
46+
contextWindow: 1_050_000,
47+
inputPrice: 2,
48+
outputPrice: 10,
49+
cacheWritesPrice: 2.5,
50+
cacheReadsPrice: 0.1,
51+
},
52+
])
53+
expect(openAiCodexModels["gpt-6.1-terra"]).toMatchObject({
54+
maxTokens: 128_000,
55+
contextWindow: 872_000,
56+
includedTools: ["apply_patch"],
57+
excludedTools: ["apply_diff", "write_to_file"],
58+
supportsImages: true,
59+
supportsPromptCache: true,
60+
supportsReasoningEffort: ["low", "medium", "high", "xhigh", "max"],
61+
requiredReasoningEffort: true,
62+
reasoningEffort: "low",
63+
supportsTemperature: false,
64+
supportsVerbosity: true,
65+
inputPrice: 0,
66+
outputPrice: 0,
67+
})
68+
})
69+
570
it("describes GPT-6.1 Sol pricing and required reasoning without changing defaults", () => {
671
expect(openAiNativeDefaultModelId).toBe("gpt-5.6-sol")
772
expect(openAiCodexDefaultModelId).toBe("gpt-5.6-sol")

‎packages/types/src/providers/openai-codex.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ export const openAiCodexDefaultModelId: OpenAiCodexModelId = "gpt-5.6-sol"
3131
* Costs are 0 as they are covered by the subscription.
3232
*/
3333
export const openAiCodexModels = {
34+
// https://github.com/openai/codex/blob/main/codex-rs/models-manager/models.json
35+
"gpt-6.1-terra": {
36+
maxTokens: 128000,
37+
// Use Codex's supported maximum rather than its 500K default compaction budget.
38+
contextWindow: 872000,
39+
includedTools: ["apply_patch"],
40+
excludedTools: ["apply_diff", "write_to_file"],
41+
supportsImages: true,
42+
supportsPromptCache: true,
43+
supportsReasoningEffort: ["low", "medium", "high", "xhigh", "max"],
44+
requiredReasoningEffort: true,
45+
reasoningEffort: "low",
46+
inputPrice: 0,
47+
outputPrice: 0,
48+
supportsVerbosity: true,
49+
supportsTemperature: false,
50+
description:
51+
"GPT-6.1 Terra: Fast, efficient visual reasoning, precise computer use, and natural writing via ChatGPT subscription",
52+
},
3453
// https://github.com/openai/codex/blob/main/codex-rs/models-manager/models.json
3554
"gpt-6.1-sol": {
3655
maxTokens: 128000,

‎packages/types/src/providers/openai.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,51 @@ export const OPENAI_API_PROTOCOL = "openai"
2424
export const openAiNativeDefaultModelId: OpenAiNativeModelId = "gpt-5.6-sol"
2525

2626
export const openAiNativeModels = {
27+
// https://developers.openai.com/api/docs/models/gpt-6.1-terra
28+
"gpt-6.1-terra": {
29+
maxTokens: 128000,
30+
contextWindow: 1_050_000,
31+
includedTools: ["apply_patch"],
32+
excludedTools: ["apply_diff", "write_to_file"],
33+
supportsImages: true,
34+
supportsPromptCache: true,
35+
supportsReasoningEffort: ["none", "low", "medium", "high", "xhigh", "max"],
36+
reasoningEffort: "medium",
37+
inputPrice: 1,
38+
outputPrice: 5,
39+
cacheWritesPrice: 1.25,
40+
cacheWritesPrice12h: 2.5,
41+
cacheReadsPrice: 0.05,
42+
longContextPricing: {
43+
thresholdTokens: 272_000,
44+
inputPriceMultiplier: 2,
45+
outputPriceMultiplier: 1.5,
46+
cacheWritesPriceMultiplier: 2,
47+
cacheReadsPriceMultiplier: 2,
48+
appliesToServiceTiers: ["default", "flex", "priority"],
49+
},
50+
supportsVerbosity: true,
51+
supportsTemperature: false,
52+
tiers: [
53+
{
54+
name: "flex",
55+
contextWindow: 1_050_000,
56+
inputPrice: 0.5,
57+
outputPrice: 2.5,
58+
cacheWritesPrice: 0.625,
59+
cacheReadsPrice: 0.025,
60+
},
61+
{
62+
name: "priority",
63+
contextWindow: 1_050_000,
64+
inputPrice: 2,
65+
outputPrice: 10,
66+
cacheWritesPrice: 2.5,
67+
cacheReadsPrice: 0.1,
68+
},
69+
],
70+
description: "GPT-6.1 Terra: Fast, efficient visual reasoning, precise computer use, and natural writing",
71+
},
2772
// https://developers.openai.com/api/docs/models/gpt-6.1-sol
2873
"gpt-6.1-sol": {
2974
maxTokens: 128000,
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
vitest.mock("@roo-code/telemetry", () => ({
2+
TelemetryService: { instance: { captureException: vitest.fn() } },
3+
}))
4+
5+
import type { ApiHandlerOptions } from "../../../shared/api"
6+
import { openAiCodexOAuthManager } from "../../../integrations/openai-codex/oauth"
7+
import { asyncStreamFrom, collectStream } from "../../../test-utils/stream"
8+
import { OpenAiNativeHandler } from "../openai-native"
9+
import { OpenAiCodexHandler } from "../openai-codex"
10+
11+
const reasoningCases: { options: ApiHandlerOptions; native: string | undefined; codex: string }[] = [
12+
{ options: {}, native: "medium", codex: "low" },
13+
{ options: { reasoningEffort: "none" }, native: "none", codex: "low" },
14+
{ options: { reasoningEffort: "minimal" }, native: "medium", codex: "low" },
15+
{ options: { reasoningEffort: "disable" }, native: undefined, codex: "low" },
16+
{ options: { enableReasoningEffort: false }, native: undefined, codex: "low" },
17+
...(["low", "medium", "high", "xhigh", "max"] as const).map((effort) => ({
18+
options: { reasoningEffort: effort },
19+
native: effort,
20+
codex: effort,
21+
})),
22+
]
23+
24+
describe("GPT-6.1 Terra requests", () => {
25+
afterEach(() => vitest.restoreAllMocks())
26+
27+
it.each(reasoningCases)("uses supported reasoning for $options", ({ options, native, codex }) => {
28+
const settings = { apiModelId: "gpt-6.1-terra", openAiNativeApiKey: "test-key", ...options }
29+
const nativeHandler = new OpenAiNativeHandler(settings)
30+
const codexHandler = new OpenAiCodexHandler(settings)
31+
expect(nativeHandler.getModel().id).toBe("gpt-6.1-terra")
32+
expect(codexHandler.getModel().id).toBe("gpt-6.1-terra")
33+
expect(nativeHandler["getReasoningEffort"](nativeHandler.getModel())).toBe(native)
34+
expect(codexHandler["getReasoningEffort"](codexHandler.getModel())).toBe(codex)
35+
})
36+
37+
it("builds native Responses tool requests with verified pricing and no temperature", () => {
38+
const handler = new OpenAiNativeHandler({
39+
apiModelId: "gpt-6.1-terra",
40+
openAiNativeApiKey: "test-key",
41+
openAiNativeServiceTier: "priority",
42+
modelTemperature: 0.7,
43+
})
44+
const model = handler.getModel()
45+
const body = handler["buildRequestBody"](model, [], "System", "low", handler["getReasoningEffort"](model), {
46+
taskId: "terra-task",
47+
tools: [
48+
{ type: "function", function: { name: "read_file", parameters: { type: "object", properties: {} } } },
49+
],
50+
})
51+
expect(body).toMatchObject({
52+
model: "gpt-6.1-terra",
53+
max_output_tokens: 128_000,
54+
reasoning: { effort: "medium" },
55+
service_tier: "priority",
56+
tools: [{ type: "function", name: "read_file", strict: true }],
57+
})
58+
expect(body).not.toHaveProperty("temperature")
59+
expect(handler["applyServiceTierPricing"](model.info, "priority")).toMatchObject({
60+
inputPrice: 2,
61+
outputPrice: 10,
62+
cacheReadsPrice: 0.1,
63+
cacheWritesPrice: 2.5,
64+
})
65+
})
66+
67+
it("routes Codex tool requests through Responses Lite with Fast mode and required reasoning", async () => {
68+
const handler = new OpenAiCodexHandler({
69+
apiModelId: "gpt-6.1-terra",
70+
reasoningEffort: "none",
71+
openAiCodexServiceTier: "priority",
72+
})
73+
vitest.spyOn(openAiCodexOAuthManager, "getAccessToken").mockResolvedValue("test-token")
74+
vitest.spyOn(openAiCodexOAuthManager, "getAccountId").mockResolvedValue("test-account")
75+
const create = vitest.fn().mockResolvedValue(asyncStreamFrom([]))
76+
Reflect.set(handler, "client", { responses: { create } })
77+
await collectStream(
78+
handler.createMessage("System", [{ role: "user", content: "Read the file" }], {
79+
taskId: "terra-task",
80+
tools: [
81+
{
82+
type: "function",
83+
function: { name: "read_file", parameters: { type: "object", properties: {} } },
84+
},
85+
],
86+
}),
87+
)
88+
expect(create).toHaveBeenCalledWith(
89+
expect.objectContaining({
90+
model: "gpt-6.1-terra",
91+
service_tier: "priority",
92+
prompt_cache_key: "terra-task",
93+
reasoning: { effort: "low", summary: "auto", context: "all_turns" },
94+
tool_choice: "auto",
95+
parallel_tool_calls: false,
96+
input: expect.arrayContaining([
97+
expect.objectContaining({
98+
type: "additional_tools",
99+
tools: [expect.objectContaining({ type: "function", name: "read_file" })],
100+
}),
101+
]),
102+
}),
103+
expect.objectContaining({
104+
headers: expect.objectContaining({
105+
"x-openai-internal-codex-responses-lite": "true",
106+
"session-id": "terra-task",
107+
}),
108+
}),
109+
)
110+
const body = create.mock.calls[0][0]
111+
expect(body).not.toHaveProperty("instructions")
112+
expect(body).not.toHaveProperty("tools")
113+
expect(body).not.toHaveProperty("max_output_tokens")
114+
expect(body).not.toHaveProperty("temperature")
115+
})
116+
})

‎src/api/providers/openai-codex.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ type OpenAiCodexRequestServiceTier = typeof OpenAiCodexServiceTier.Priority
4848
const CODEX_API_BASE_URL = "https://chatgpt.com/backend-api/codex"
4949
const LUNA_MODEL_ID = "gpt-5.6-luna"
5050
const LUNA_CODEX_VERSION = "0.144.0"
51-
const RESPONSES_LITE_MODEL_IDS = new Set<OpenAiCodexModelId>([LUNA_MODEL_ID, "gpt-6-astra", "gpt-6.1-sol"])
51+
const RESPONSES_LITE_MODEL_IDS = new Set<OpenAiCodexModelId>([
52+
LUNA_MODEL_ID,
53+
"gpt-6-astra",
54+
"gpt-6.1-sol",
55+
"gpt-6.1-terra",
56+
])
5257

5358
/**
5459
* A refusal is streamed as text so the chat still shows why the model declined, but it is not part

0 commit comments

Comments
 (0)