Codex
Use XiaoYuan AI with Codex, the AI coding assistant.
Prerequisites
- Codex installed
- API key from https://ai.xiaoyuan.co.uk
Configuration
Codex supports OpenAI-compatible API endpoints, making it easy to use with XiaoYuan AI.
Step 1: Open Codex Settings
Access Codex settings through:
- Menu: Preferences → Settings
- Keyboard:
Cmd/Ctrl + , - Command palette: Search for "Settings"
Step 2: Configure API Settings
Find the API configuration section and set:
| Setting | Value |
|---|---|
| API Provider | OpenAI Compatible / Custom |
| Base URL | https://ai.xiaoyuan.co.uk/v1 |
| API Key | Your XiaoYuan API key |
| Model | claude-opus-4-8 |
Configuration File
Alternatively, edit Codex's configuration file directly:
{
"api": {
"provider": "openai-compatible",
"baseUrl": "https://ai.xiaoyuan.co.uk/v1",
"apiKey": "your-api-key-here",
"model": "claude-opus-4-8"
}
}{
"api": {
"provider": "openai-compatible",
"baseUrl": "https://ai.xiaoyuan.co.uk/v1",
"apiKey": "your-api-key-here",
"model": "claude-opus-4-8"
}
}Using Environment Variables
For better security, use environment variables:
export CODEX_API_KEY="your-xiaoyuan-api-key"
export CODEX_BASE_URL="https://ai.xiaoyuan.co.uk/v1"
export CODEX_MODEL="claude-opus-4-8"Then in config:
{
"api": {
"provider": "openai-compatible",
"baseUrl": "${CODEX_BASE_URL}",
"apiKey": "${CODEX_API_KEY}",
"model": "${CODEX_MODEL}"
}
}Usage
Once configured, Codex will use Claude 4.8 for all AI interactions:
Chat Interface
Ask Claude anything about your code...Code Generation
Use Codex commands to generate code:
Cmd/Ctrl + K- Generate codeCmd/Ctrl + I- Inline suggestionsCmd/Ctrl + Shift + P- Command palette
Code Explanation
Select code and ask Codex to explain it:
- Highlight code
- Right-click → Codex: Explain
- Get explanation from Claude 4.8
Refactoring
Ask Codex to refactor code:
- Select code to refactor
- Right-click → Codex: Refactor
- Describe desired changes
Advanced Features
Custom Prompts
Create custom prompts in Codex settings:
{
"customPrompts": [
{
"name": "Document Function",
"prompt": "Add comprehensive documentation to this function including JSDoc comments, parameter descriptions, return value, and usage examples."
},
{
"name": "Optimize Performance",
"prompt": "Analyze this code for performance issues and suggest optimizations."
}
]
}Model Parameters
Fine-tune Claude's behavior:
{
"api": {
"baseUrl": "https://ai.xiaoyuan.co.uk/v1",
"apiKey": "your-api-key-here",
"model": "claude-opus-4-8",
"parameters": {
"temperature": 0.7,
"max_tokens": 4096,
"top_p": 0.9
}
}
}Context Management
Configure how much code context Codex sends:
{
"context": {
"includeOpenFiles": true,
"includeGitDiff": true,
"maxTokens": 100000
}
}Verification
Test your setup:
- Open Codex
- Start a new chat
- Ask: "What model are you?"
- Claude should identify as Opus 4.8
Or run a code generation task to verify it's working.
Troubleshooting
Connection Failed
If Codex can't connect to XiaoYuan AI:
- Check the base URL:
https://ai.xiaoyuan.co.uk/v1 - Verify your API key
- Test with curl:
curl https://ai.xiaoyuan.co.uk/v1/models \
-H "Authorization: Bearer your-api-key-here"Slow Response Times
If responses are slow:
- Check your internet connection
- Reduce context size in settings
- Lower
max_tokensparameter - Check API status at https://ai.xiaoyuan.co.uk
Authentication Errors
Error: Invalid API keySolutions:
- Verify API key is correct
- Regenerate API key at https://ai.xiaoyuan.co.uk
- Check for extra spaces in configuration
- Ensure key hasn't expired
Model Not Available
Error: Model not foundEnsure model name is exactly:
claude-opus-4-8(recommended)claude-opus-4.8claude-opus-4-latest
Tips & Best Practices
1. Use Specific Prompts
Instead of:
"Fix this"
Try:
"Refactor this function to improve readability, add error handling, and follow Python PEP 8 style guidelines"
2. Provide Context
Give Claude context about your project:
- Select relevant code files
- Describe the project structure
- Mention frameworks and libraries used
3. Iterative Refinement
Work iteratively:
- Generate initial code
- Review and test
- Ask for specific improvements
- Repeat until satisfied
4. Leverage Chat History
Claude maintains conversation context:
- Reference previous exchanges
- Build on earlier suggestions
- Ask follow-up questions
Integration with IDEs
VS Code
Install Codex extension for VS Code:
code --install-extension codex.vscode-codexConfigure in VS Code settings.json:
{
"codex.api.baseUrl": "https://ai.xiaoyuan.co.uk/v1",
"codex.api.apiKey": "your-api-key-here",
"codex.api.model": "claude-opus-4-8"
}Neovim
Add to your Neovim config:
require('codex').setup({
api = {
base_url = 'https://ai.xiaoyuan.co.uk/v1',
api_key = os.getenv('XIAOYUAN_API_KEY'),
model = 'claude-opus-4-8'
}
})Support
Need help?
- Check Getting Started
- Review API Key guide
- Visit https://ai.xiaoyuan.co.uk for support