OpenAI Codex — sx_provider_codex.c

Provider Codex

Approfondimento sul provider OpenAI Codex — modelli, autenticazione, funzionalità e configurazione.

Panoramica

Il provider Codex collega scorpiox code al backend OpenAI Codex tramite autenticazione OAuth Bearer. Si rivolge all'API backend di ChatGPT e supporta streaming, pensiero esteso, uso di strumenti, chiamate a funzioni, visione e aggiornamento automatico dei token.

# 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

Modelli supportati

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.

Funzionalità

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

Autenticazione

Codex utilizza l'autenticazione tramite token OAuth Bearer nell'header Authorization. I token sono gestiti da scorpiox-codex-fetchtoken e possono essere ottenuti da tre sorgenti:

Sorgenti token

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.

Configurazione

Tutte le impostazioni Codex sono memorizzate in scorpiox-env.txt nella root del progetto. Esegui scorpiox-config per configurare interattivamente.

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

Avvio rapido

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

Confronto provider

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

Implementazione sorgente

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.