Connect Codex or Claude Code directly to LinkAI ModelHub

Choose your coding tool first, then follow the steps for your operating system.
Tool
System

Configuration steps

Download Codex, get a LinkAI API Key, then write the Codex provider configuration.

1

Install Codex

Download and install the Codex desktop app for macOS.

Go to download

2

Get or reuse a LinkAI API Key

Sign in to LinknLink AI, create an API Key, and copy the value that starts with sk-. If you already have a valid LinkAI API Key, use that key directly.

Get API Key

Paste a key that starts with sk-. If valid, the commands below update automatically. The key is not saved.

Keep the key private. The current command value is sk-replace-with-your-LinkAI-key, and the current model is gpt-5.6-sol.

3

Set the API key environment variable

Open Terminal first: press Command + Space, search Terminal, and press Enter. Then write the key to ~/.zshrc. For the Codex desktop app or VS Code launched from Finder, also write the macOS GUI environment variable.

Copy and run
echo 'export OPENAI_API_KEY="sk-replace-with-your-LinkAI-key"' >> ~/.zshrc
source ~/.zshrc

launchctl setenv OPENAI_API_KEY "sk-replace-with-your-LinkAI-key"
4

Back up and write the Codex config

You can copy and run this command directly. It backs up the current config first, then writes a minimal LinkAI config.

Copy and run
mkdir -p ~/.codex/backups
cp ~/.codex/config.toml ~/.codex/backups/config.toml.before-linkai.$(date +%Y%m%d%H%M%S) 2>/dev/null || true

cat > ~/.codex/config.toml <<'EOF'
model = "gpt-5.6-sol"
model_provider = "linkai"

[model_providers.linkai]
name = "LinkAI"
base_url = "https://api.linknlink.ai/modelhub/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"
requires_openai_auth = false
EOF

New users can copy and run this command directly. If you already use MCP, plugins, or project trust settings in Codex, keep your existing file and manually add or update only model, model_provider, and the [model_providers.linkai] block shown above.

5

Restart and verify

Fully quit Codex before reopening it. On macOS, use Codex > Quit Codex, and check Activity Monitor if needed. If it still opens the login page, restart the computer, then open Codex and send reply only ok.

Restore official Codex configuration

Use this when you stop using a LinkAI Key or want to return to the official ChatGPT / Codex account flow.

1

Quit and back up

Copy and run
osascript -e 'quit app "Codex"' 2>/dev/null || true
pkill -x Codex 2>/dev/null || true

mkdir -p ~/.codex/backups
cp ~/.codex/config.toml ~/.codex/backups/config.toml.before-restore-official.$(date +%Y%m%d%H%M%S)
2

Remove the LinkAI provider

Copy and run
cat > ~/.codex/config.toml <<'EOF'
# Official Codex uses your ChatGPT / Codex account.
# Leave this file without a LinkAI model_provider block.
EOF

launchctl unsetenv OPENAI_API_KEY
launchctl unsetenv OPENAI_API_KEY_EUMODELHUB

If the original config includes MCP, plugins, or project trust settings, do not overwrite the entire file. Manually remove model_provider = "linkai" and the [model_providers.linkai] block.

FAQ

Common checks for LinkAI direct connection and restoring the official config.

Where do I get a LinkAI API Key?

Sign in to LinknLink AI, create an API Key, and copy the value that starts with sk-. If you already have a valid LinkAI API Key, use it directly in the configuration steps.

Codex desktop app cannot read the API Key?

On macOS, desktop apps may not read ~/.zshrc. Run launchctl setenv OPENAI_API_KEY "sk-...", confirm with launchctl getenv OPENAI_API_KEY, then fully quit and reopen Codex.

Can I use the VS Code extension?

Yes. Install the Codex desktop app and verify Codex CLI first, then install the official ChatGPT / Codex extension in VS Code. If VS Code returns 401 while CLI works, fully quit and reopen VS Code. On macOS, set the key with launchctl setenv before restarting VS Code.

Will these commands overwrite my existing Codex config?

The minimal config commands replace config.toml after creating a backup. If you already use MCP, plugins, or project trust settings, manually merge the LinkAI provider block instead.

Seeing stream closed before response.completed?

This usually means the server-side Responses API stream did not send the final response.completed event. Confirm that the deployed service supports the Codex Responses streaming protocol.

Seeing model_not_found?

Confirm that the configured model matches your billing mode: API billing uses gpt-5.6-sol, and Token Plan uses linkai.

How do I confirm official config is restored?

On macOS and Windows, fully quit and reopen Codex. If the official login flow appears again, the LinkAI provider has been removed. On Linux, check that ~/.codex/config.toml no longer contains model_provider = "linkai" or [model_providers.linkai], then verify with Codex CLI.