OpenAI Codex — sx_provider_codex.c

Codex 提供商

深入了解 OpenAI Codex 提供商 — 模型、認證、功能和配置。

概述

Codex 提供商透過 OAuth Bearer 令牌認證將 scorpiox code 連接到 OpenAI Codex 後端。它針對 ChatGPT 後端 API,支援串流傳輸、擴展思考、工具使用、函數呼叫、視覺和自動令牌重新整理。

# API endpoint
POST https://chatgpt.com/backend-api/codex/responses

# Auth header
Authorization: Bearer <oauth_token>

# Source file
impl: scorpiox/libsxnet/sx_provider_codex.c

支援的模型

gpt-5.3-codex
Flagship
Latest Codex flagship model. Maximum reasoning depth, extended context, best for complex multi-file refactors and architecture work.
gpt-5.3-codex-spark
Spark
Lightweight 5.3 variant optimized for speed. Best for quick edits, completions, and interactive coding sessions.
gpt-5.2-codex
Standard
Previous-generation flagship. Proven reliability for production workloads and general-purpose coding tasks.
gpt-5.2
Standard
General GPT-5.2 model. Broader capabilities beyond code — documentation, analysis, and reasoning.
gpt-5.1-codex
Standard
Stable 5.1 generation. Well-tested for day-to-day development tasks with consistent output quality.
gpt-5.1-codex-mini
Mini
Compact 5.1 variant. Lower latency and cost, ideal for simple tasks like formatting, renaming, and boilerplate.
gpt-5.1-codex-max
Max
Maximum-capacity 5.1 model. Extended thinking budget and larger context window for deep analysis.

功能

Streaming
Real-time token streaming via SSE for responsive TUI output
🧠
Extended Thinking
Chain-of-thought reasoning with configurable thinking budget
🔧
Tool Use
Full tool execution — file ops, bash, search, docs, and more
📞
Function Calling
Native OpenAI function calling for structured tool invocations
👁️
Vision
Image input support for screenshots, diagrams, and UI reviews
🔄
Token Refresh
Automatic OAuth token rotation via scorpiox-codex-fetchtoken

認證

Codex 透過 Authorization 標頭使用 OAuth Bearer 令牌認證。令牌由 scorpiox-codex-fetchtoken 管理,可從三個來源取得:

令牌來源

Local CODEX_TOKEN_SOURCE=local
Reads the OAuth token from a local file managed by scorpiox-codex-fetchtoken. Default mode — no network calls needed for token acquisition. The token file is stored alongside your scorpiox configuration.
Remote CODEX_TOKEN_SOURCE=remote
Fetches the token from a remote HTTP endpoint configured via CODEX_REMOTE_URL. Default URL: https://token.scorpiox.net/codex. Useful for centralized token management across teams.
SSH CODEX_TOKEN_SOURCE=ssh
Retrieves the token over SSH from a remote machine. Configure via CODEX_SSH_HOST, CODEX_SSH_USER, CODEX_SSH_PASS, and CODEX_SSH_PORT. Ideal for air-gapped or private infrastructure environments.

配置

所有 Codex 設定儲存在專案根目錄的 scorpiox-env.txt 中。執行 scorpiox-config 進行互動式配置。

KeyDescriptionDefault
PROVIDERSet to codex to use this providerscorpiox
MODELModel name or alias (e.g. gpt-5.3-codex)sonnet
TOOLSEnable/disable all tool execution1
CODEX_TOKEN_SOURCEToken acquisition method: local, remote, sshlocal
CODEX_REMOTE_URLRemote HTTP endpoint for token fetchinghttps://token.scorpiox.net/codex
CODEX_SSH_HOSTSSH hostname for remote token retrieval
CODEX_SSH_USERSSH username
CODEX_SSH_PASSSSH password
CODEX_SSH_PORTSSH port number

快速開始

1. Switch to Codex provider

# In scorpiox-env.txt
PROVIDER=codex
MODEL=gpt-5.3-codex
CODEX_TOKEN_SOURCE=local

# Or use scorpiox-config interactively
$ scorpiox-config

2. Fetch your token

# Local token (default)
$ scorpiox-codex-fetchtoken

# Remote token from team server
$ CODEX_TOKEN_SOURCE=remote scorpiox-codex-fetchtoken

# SSH token from bastion host
$ CODEX_TOKEN_SOURCE=ssh CODEX_SSH_HOST=bastion.internal scorpiox-codex-fetchtoken

3. Start coding

# Launch scorpiox code with Codex backend
$ sx

# Or specify model inline
$ sx --provider codex --model gpt-5.3-codex-spark

提供商對比

FeatureCodexClaude CodeAnthropicGeminiOpenAIRouter
Streaming
Thinking
Tool Use
Function Calling
Vision
Token Refresh
Context Caching
Auth MethodOAuth BearerOAuth Bearerx-api-keyAPI KeyAPI KeyNone

源實現

The Codex provider is implemented as a single-file C module following the scorpiox provider interface pattern:

// Provider source
scorpiox/libsxnet/sx_provider_codex.c

// Token fetcher binary
scorpiox/scorpiox-codex-fetchtoken.c

// Provider interface (shared by all providers)
scorpiox/libsxnet/sx_provider.h

// Config integration
scorpiox/libsxutil/sx_config.c → CODEX_TOKEN_SOURCE, MODEL

All providers compile as part of libsxnet and are statically linked into the sx binary. Zero runtime dependencies — the Codex provider uses raw socket HTTP built into scorpiox's networking layer.