Both Droid and Pi connect to 4AICode through an OpenAI-compatible interface.
- Base URL:
https://relay.4aicode.com/v1 - API key: An
sk-4ai-...token created under Dashboard → Manage Tokens - Recommended model:
gpt-5.6-terra; usegpt-6-astrafor flagship tasks andgpt-5.4-miniorgemini-3.8-flashfor lightweight tasks
Droid
Droid is Factory's command-line coding agent. See Factory BYOK for the official documentation.
First, store your 4AICode token in an environment variable:
export RELAY4AI_API_KEY=sk-4ai-xxxxxxxxxxxxxxxx
Edit ~/.factory/settings.json:
{
"customModels": [
{
"model": "4aicode-gpt-5.6-terra",
"displayName": "4AICode GPT 5.6 Terra",
"baseUrl": "https://relay.4aicode.com/v1",
"apiKey": "${RELAY4AI_API_KEY}",
"provider": "generic-chat-completion-api",
"maxOutputTokens": 16384,
"index": 0,
"id": "custom:4AICode-GPT-5.6-Terra-0"
},
{
"model": "4aicode-gpt-5.6-sol",
"displayName": "4AICode GPT 5.6 Sol",
"baseUrl": "https://relay.4aicode.com/v1",
"apiKey": "${RELAY4AI_API_KEY}",
"provider": "generic-chat-completion-api",
"maxOutputTokens": 16384,
"index": 1,
"id": "custom:4AICode-GPT-5.6-Sol-1"
},
{
"model": "4aicode-gpt-6-astra",
"displayName": "4AICode GPT 6 Astra",
"baseUrl": "https://relay.4aicode.com/v1",
"apiKey": "${RELAY4AI_API_KEY}",
"provider": "generic-chat-completion-api",
"maxOutputTokens": 16384,
"index": 2,
"id": "custom:4AICode-GPT-6-Astra-2"
},
{
"model": "4aicode-gpt-5.4-mini",
"displayName": "4AICode GPT 5.4 Mini",
"baseUrl": "https://relay.4aicode.com/v1",
"apiKey": "${RELAY4AI_API_KEY}",
"provider": "generic-chat-completion-api",
"maxOutputTokens": 16384,
"index": 3,
"id": "custom:4AICode-GPT-5.4-Mini-3"
},
{
"model": "gemini-3.8-flash",
"displayName": "4AICode Gemini 3.8 Flash",
"baseUrl": "https://relay.4aicode.com/v1",
"apiKey": "${RELAY4AI_API_KEY}",
"provider": "generic-chat-completion-api",
"maxOutputTokens": 16384,
"index": 4,
"id": "custom:4AICode-Gemini-3.8-Flash-4"
}
],
"model": "custom:4AICode-GPT-5.6-Terra-0",
"sessionDefaultSettings": {
"model": "custom:4AICode-GPT-5.6-Terra-0"
}
}
After saving the file, restart Droid. Run droid to enter interactive mode, then use /model to select 4AICode GPT 5.6 Terra.
The 4aicode-gpt-* aliases are used intentionally instead of specifying gpt-5.6-terra directly. This makes Droid treat the model as a generic Chat Completions model. The 4AICode gateway then maps the alias to the actual Codex model, preventing GPT-5 / Responses API provider validation warnings at startup.
Example in headless mode:
droid exec --model "custom:4AICode-GPT-5.6-Terra-0" "summarize this repository"
Explicitly select Sol when you need the flagship model:
droid exec --model "custom:4AICode-GPT-5.6-Sol-1" "refactor this repository"
To use the lightweight model:
droid exec --model "custom:4AICode-GPT-5.4-Mini-3" "fix typos in docs"
To use Gemini 3.8 Flash:
droid exec --model "custom:4AICode-Gemini-3.8-Flash-4" "analyze this repository"
Pi
Pi is the command-line coding agent from pi.dev. Its custom model configuration file is ~/.pi/agent/models.json. See Pi Custom Models for the official documentation.
First, store your 4AICode token in an environment variable:
export RELAY4AI_API_KEY=sk-4ai-xxxxxxxxxxxxxxxx
Edit ~/.pi/agent/models.json. When referencing an environment variable in Pi's apiKey, include the $ prefix: $RELAY4AI_API_KEY.
{
"providers": {
"4aicode": {
"baseUrl": "https://relay.4aicode.com/v1",
"api": "openai-responses",
"apiKey": "$RELAY4AI_API_KEY",
"authHeader": true,
"models": [
{
"id": "gpt-5.6-terra",
"name": "4AICode GPT 5.6 Terra",
"reasoning": true,
"maxTokens": 16384
},
{
"id": "gpt-5.6-sol",
"name": "4AICode GPT 5.6 Sol",
"reasoning": true,
"maxTokens": 16384
},
{
"id": "gpt-6-astra",
"name": "4AICode GPT 6 Astra",
"reasoning": true,
"maxTokens": 16384
},
{
"id": "gpt-5.4-mini",
"name": "4AICode GPT 5.4 Mini",
"reasoning": true,
"maxTokens": 16384
},
{
"id": "gemini-3.8-flash",
"name": "4AICode Gemini 3.8 Flash",
"reasoning": false,
"maxTokens": 16384
}
]
}
}
}
Run:
pi --provider 4aicode --model gpt-5.6-terra
You can also use /model in Pi's interactive interface to switch to 4AICode GPT 5.6 Terra.
Explicitly select Sol when you need the flagship model:
pi --provider 4aicode --model gpt-5.6-sol
Use Astra:
pi --provider 4aicode --model gpt-6-astra
To use Gemini 3.8 Flash:
pi --provider 4aicode --model gemini-3.8-flash
Verification
After completing the configuration, send a ping message. Then open Dashboard → Usage History. If the corresponding model appears in the request history, the configuration was successful.
Verify using Gemini 3.8 Flash:
pi --provider 4aicode --model gemini-3.8-flash "ping"