Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions packages/types/src/__tests__/openai-models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,71 @@ import { openAiCodexDefaultModelId, openAiCodexModels } from "../providers/opena
import { openAiNativeDefaultModelId, openAiNativeModels } from "../providers/openai.js"

describe("OpenAI native models", () => {
it("describes GPT-6.1 Terra pricing and optional native reasoning without changing defaults", () => {
expect(openAiNativeDefaultModelId).toBe("gpt-5.6-sol")
expect(openAiCodexDefaultModelId).toBe("gpt-5.6-sol")
const model = openAiNativeModels["gpt-6.1-terra"]
expect(model).toMatchObject({
maxTokens: 128_000,
contextWindow: 1_050_000,
includedTools: ["apply_patch"],
excludedTools: ["apply_diff", "write_to_file"],
supportsImages: true,
supportsPromptCache: true,
supportsReasoningEffort: ["none", "low", "medium", "high", "xhigh", "max"],
reasoningEffort: "medium",
supportsTemperature: false,
supportsVerbosity: true,
inputPrice: 1,
outputPrice: 5,
cacheWritesPrice: 1.25,
cacheWritesPrice12h: 2.5,
cacheReadsPrice: 0.05,
longContextPricing: {
thresholdTokens: 272_000,
inputPriceMultiplier: 2,
outputPriceMultiplier: 1.5,
cacheWritesPriceMultiplier: 2,
cacheReadsPriceMultiplier: 2,
appliesToServiceTiers: ["default", "flex", "priority"],
},
})
expect(model).not.toHaveProperty("requiredReasoningEffort", true)
expect(model.tiers).toEqual([
{
name: "flex",
contextWindow: 1_050_000,
inputPrice: 0.5,
outputPrice: 2.5,
cacheWritesPrice: 0.625,
cacheReadsPrice: 0.025,
},
{
name: "priority",
contextWindow: 1_050_000,
inputPrice: 2,
outputPrice: 10,
cacheWritesPrice: 2.5,
cacheReadsPrice: 0.1,
},
])
expect(openAiCodexModels["gpt-6.1-terra"]).toMatchObject({
maxTokens: 128_000,
contextWindow: 872_000,
includedTools: ["apply_patch"],
excludedTools: ["apply_diff", "write_to_file"],
supportsImages: true,
supportsPromptCache: true,
supportsReasoningEffort: ["low", "medium", "high", "xhigh", "max"],
requiredReasoningEffort: true,
reasoningEffort: "low",
supportsTemperature: false,
supportsVerbosity: true,
inputPrice: 0,
outputPrice: 0,
})
})

it("describes GPT-6.1 Sol pricing and required reasoning without changing defaults", () => {
expect(openAiNativeDefaultModelId).toBe("gpt-5.6-sol")
expect(openAiCodexDefaultModelId).toBe("gpt-5.6-sol")
Expand Down
19 changes: 19 additions & 0 deletions packages/types/src/providers/openai-codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ export const openAiCodexDefaultModelId: OpenAiCodexModelId = "gpt-5.6-sol"
* Costs are 0 as they are covered by the subscription.
*/
export const openAiCodexModels = {
// https://github.com/openai/codex/blob/main/codex-rs/models-manager/models.json
"gpt-6.1-terra": {
maxTokens: 128000,
// Use Codex's supported maximum rather than its 500K default compaction budget.
contextWindow: 872000,
includedTools: ["apply_patch"],
excludedTools: ["apply_diff", "write_to_file"],
supportsImages: true,
supportsPromptCache: true,
supportsReasoningEffort: ["low", "medium", "high", "xhigh", "max"],
requiredReasoningEffort: true,
reasoningEffort: "low",
inputPrice: 0,
outputPrice: 0,
supportsVerbosity: true,
supportsTemperature: false,
description:
"GPT-6.1 Terra: Fast, efficient visual reasoning, precise computer use, and natural writing via ChatGPT subscription",
},
// https://github.com/openai/codex/blob/main/codex-rs/models-manager/models.json
"gpt-6.1-sol": {
maxTokens: 128000,
Expand Down
45 changes: 45 additions & 0 deletions packages/types/src/providers/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,51 @@ export const OPENAI_API_PROTOCOL = "openai"
export const openAiNativeDefaultModelId: OpenAiNativeModelId = "gpt-5.6-sol"

export const openAiNativeModels = {
// https://developers.openai.com/api/docs/models/gpt-6.1-terra
"gpt-6.1-terra": {
maxTokens: 128000,
contextWindow: 1_050_000,
includedTools: ["apply_patch"],
excludedTools: ["apply_diff", "write_to_file"],
supportsImages: true,
supportsPromptCache: true,
supportsReasoningEffort: ["none", "low", "medium", "high", "xhigh", "max"],
reasoningEffort: "medium",
inputPrice: 1,
outputPrice: 5,
cacheWritesPrice: 1.25,
cacheWritesPrice12h: 2.5,
cacheReadsPrice: 0.05,
longContextPricing: {
thresholdTokens: 272_000,
inputPriceMultiplier: 2,
outputPriceMultiplier: 1.5,
cacheWritesPriceMultiplier: 2,
cacheReadsPriceMultiplier: 2,
appliesToServiceTiers: ["default", "flex", "priority"],
},
supportsVerbosity: true,
supportsTemperature: false,
tiers: [
{
name: "flex",
contextWindow: 1_050_000,
inputPrice: 0.5,
outputPrice: 2.5,
cacheWritesPrice: 0.625,
cacheReadsPrice: 0.025,
},
{
name: "priority",
contextWindow: 1_050_000,
inputPrice: 2,
outputPrice: 10,
cacheWritesPrice: 2.5,
cacheReadsPrice: 0.1,
},
],
description: "GPT-6.1 Terra: Fast, efficient visual reasoning, precise computer use, and natural writing",
},
// https://developers.openai.com/api/docs/models/gpt-6.1-sol
"gpt-6.1-sol": {
maxTokens: 128000,
Expand Down
116 changes: 116 additions & 0 deletions src/api/providers/__tests__/openai-terra-6.1.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
vitest.mock("@roo-code/telemetry", () => ({
TelemetryService: { instance: { captureException: vitest.fn() } },
}))

import type { ApiHandlerOptions } from "../../../shared/api"
import { openAiCodexOAuthManager } from "../../../integrations/openai-codex/oauth"
import { asyncStreamFrom, collectStream } from "../../../test-utils/stream"
import { OpenAiNativeHandler } from "../openai-native"
import { OpenAiCodexHandler } from "../openai-codex"

const reasoningCases: { options: ApiHandlerOptions; native: string | undefined; codex: string }[] = [
{ options: {}, native: "medium", codex: "low" },
{ options: { reasoningEffort: "none" }, native: "none", codex: "low" },
{ options: { reasoningEffort: "minimal" }, native: "medium", codex: "low" },
{ options: { reasoningEffort: "disable" }, native: undefined, codex: "low" },
{ options: { enableReasoningEffort: false }, native: undefined, codex: "low" },
...(["low", "medium", "high", "xhigh", "max"] as const).map((effort) => ({
options: { reasoningEffort: effort },
native: effort,
codex: effort,
})),
]

describe("GPT-6.1 Terra requests", () => {
afterEach(() => vitest.restoreAllMocks())

it.each(reasoningCases)("uses supported reasoning for $options", ({ options, native, codex }) => {
const settings = { apiModelId: "gpt-6.1-terra", openAiNativeApiKey: "test-key", ...options }
const nativeHandler = new OpenAiNativeHandler(settings)
const codexHandler = new OpenAiCodexHandler(settings)
expect(nativeHandler.getModel().id).toBe("gpt-6.1-terra")
expect(codexHandler.getModel().id).toBe("gpt-6.1-terra")
expect(nativeHandler["getReasoningEffort"](nativeHandler.getModel())).toBe(native)
expect(codexHandler["getReasoningEffort"](codexHandler.getModel())).toBe(codex)
})

it("builds native Responses tool requests with verified pricing and no temperature", () => {
const handler = new OpenAiNativeHandler({
apiModelId: "gpt-6.1-terra",
openAiNativeApiKey: "test-key",
openAiNativeServiceTier: "priority",
modelTemperature: 0.7,
})
const model = handler.getModel()
const body = handler["buildRequestBody"](model, [], "System", "low", handler["getReasoningEffort"](model), {
taskId: "terra-task",
tools: [
{ type: "function", function: { name: "read_file", parameters: { type: "object", properties: {} } } },
],
})
expect(body).toMatchObject({
model: "gpt-6.1-terra",
max_output_tokens: 128_000,
reasoning: { effort: "medium" },
service_tier: "priority",
tools: [{ type: "function", name: "read_file", strict: true }],
})
expect(body).not.toHaveProperty("temperature")
expect(handler["applyServiceTierPricing"](model.info, "priority")).toMatchObject({
inputPrice: 2,
outputPrice: 10,
cacheReadsPrice: 0.1,
cacheWritesPrice: 2.5,
})
})

it("routes Codex tool requests through Responses Lite with Fast mode and required reasoning", async () => {
const handler = new OpenAiCodexHandler({
apiModelId: "gpt-6.1-terra",
reasoningEffort: "none",
openAiCodexServiceTier: "priority",
})
vitest.spyOn(openAiCodexOAuthManager, "getAccessToken").mockResolvedValue("test-token")
vitest.spyOn(openAiCodexOAuthManager, "getAccountId").mockResolvedValue("test-account")
const create = vitest.fn().mockResolvedValue(asyncStreamFrom([]))
Reflect.set(handler, "client", { responses: { create } })
await collectStream(
handler.createMessage("System", [{ role: "user", content: "Read the file" }], {
taskId: "terra-task",
tools: [
{
type: "function",
function: { name: "read_file", parameters: { type: "object", properties: {} } },
},
],
}),
)
expect(create).toHaveBeenCalledWith(
expect.objectContaining({
model: "gpt-6.1-terra",
service_tier: "priority",
prompt_cache_key: "terra-task",
reasoning: { effort: "low", summary: "auto", context: "all_turns" },
tool_choice: "auto",
parallel_tool_calls: false,
input: expect.arrayContaining([
expect.objectContaining({
type: "additional_tools",
tools: [expect.objectContaining({ type: "function", name: "read_file" })],
}),
]),
}),
expect.objectContaining({
headers: expect.objectContaining({
"x-openai-internal-codex-responses-lite": "true",
"session-id": "terra-task",
}),
}),
)
const body = create.mock.calls[0][0]
expect(body).not.toHaveProperty("instructions")
expect(body).not.toHaveProperty("tools")
expect(body).not.toHaveProperty("max_output_tokens")
expect(body).not.toHaveProperty("temperature")
})
})
7 changes: 6 additions & 1 deletion src/api/providers/openai-codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ type OpenAiCodexRequestServiceTier = typeof OpenAiCodexServiceTier.Priority
const CODEX_API_BASE_URL = "https://chatgpt.com/backend-api/codex"
const LUNA_MODEL_ID = "gpt-5.6-luna"
const LUNA_CODEX_VERSION = "0.144.0"
const RESPONSES_LITE_MODEL_IDS = new Set<OpenAiCodexModelId>([LUNA_MODEL_ID, "gpt-6-astra", "gpt-6.1-sol"])
const RESPONSES_LITE_MODEL_IDS = new Set<OpenAiCodexModelId>([
LUNA_MODEL_ID,
"gpt-6-astra",
"gpt-6.1-sol",
"gpt-6.1-terra",
])

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