Cài đặt "bộ não" cho OpenClaw

Chapter này bao gồm các bài viết hướng dẫn cài đặt để kết nối tới các server AI (có thể là cloud hoặc local) làm backend suy luận cho OpenClaw.

Cài đặt Codex làm backend cho OpenClaw

Mục tiêu

Cấu hình OpenClaw dùng tài khoản ChatGPT/Codex làm model provider chính.

Sau khi hoàn tất:

Lưu ý:
Cách này dùng tài khoản ChatGPT/Codex của bạn → Usage/quota dùng chung với Codex

Tóm tắt nhanh

Các bước chính:

  1. Đăng nhập OpenAI/Codex OAuth 
  2. Kiểm tra auth profile 
  3. Set model chính: openai/gpt-5.5 
  4. Xóa fallback cũ nếu có 
  5. Tùy chọn tắt thinking 
  6. Restart OpenClaw Gateway 
  7. Test qua Web UI / Discord / Telegram

Điều kiện trước khi làm

Có tài khoản ChatGPT có đăng ký subscription và có thể sử dụng Codex.

Có container OpenClaw Gateway đã chạy và có thể truy cập.

Đăng nhập OpenAI/Codex OAuth

Chạy trên Docker host:

docker exec -it openclaw-gateway \
  node dist/index.js models auth login --provider openai --device-code

OpenClaw sẽ hiện hướng dẫn đăng nhập dạng device code.

Làm theo hướng dẫn:

Khi thành công, output sẽ gần giống:

Auth profile: openai:your-email@example.com (openai/oauth)
Default model available: openai/gpt-5.5

Kiểm tra auth profile

Chạy:

docker exec -it openclaw-gateway \
  node dist/index.js models auth list --provider openai

Kết quả cần thấy profile kiểu:

openai:your-email@example.com

Nếu chưa thấy profile, chạy lại bước đăng nhập OAuth.

Đặt Codex/OpenAI làm model chính

Đặt model chính:

docker exec -it openclaw-gateway \
  node dist/index.js config set agents.defaults.model.primary openai/gpt-5.5

Xóa fallback cũ nếu có:

docker exec -it openclaw-gateway \
  node dist/index.js config unset agents.defaults.model.fallbacks

Kiểm tra lại:

docker exec -it openclaw-gateway \
  node dist/index.js config get agents.defaults.model --json

Kết quả mong muốn:

{
  "primary": "openai/gpt-5.5"
}

Restart OpenClaw Gateway

Restart container:

docker restart openclaw-gateway

Chờ 10–20 giây rồi kiểm tra log:

docker logs --tail 80 openclaw-gateway | grep -i "agent model"

Kết quả mong muốn:

[gateway] agent model: openai/gpt-5.5 (thinking=medium, fast=off)

Test qua OpenClaw

Test qua Web UI, Discord, hoặc Telegram:

Bạn đang hoạt động chưa? Trả lời ngắn gọn.

Kết quả mong muốn:

Đang hoạt động.

Nếu bot trả lời được, Codex/OpenAI đã trở thành "bộ não" chính của OpenClaw.

Phụ lục

Kiểm tra cấu hình đầy đủ

Xem cấu hình agent:

docker exec -it openclaw-gateway \
  node dist/index.js config get agents.defaults --json

Kết quả nên có:

{
  "model": {
    "primary": "openai/gpt-5.5"
  }
}

Xem trạng thái model:

docker exec -it openclaw-gateway \
  node dist/index.js models status

Hoặc xem danh sách model OpenAI:

docker exec -it openclaw-gateway \
  node dist/index.js models list --provider openai

Lưu ý về quota

Cách này dùng:

Không giống với:

Vì vậy:

Troubleshooting

Đăng nhập xong nhưng model chưa đổi

Chạy lại:

docker exec -it openclaw-gateway \
  node dist/index.js config set agents.defaults.model.primary openai/gpt-5.5

docker restart openclaw-gateway
Không thấy auth profile

Kiểm tra:

docker exec -it openclaw-gateway \
  node dist/index.js models auth list --provider openai

Nếu không có profile, đăng nhập lại:

docker exec -it openclaw-gateway \
  node dist/index.js models auth login --provider openai --device-code
Vẫn dùng provider cũ

Kiểm tra config:

docker exec -it openclaw-gateway \
  node dist/index.js config get agents.defaults --json

Nếu còn fallback cũ:

docker exec -it openclaw-gateway \
  node dist/index.js config unset agents.defaults.model.fallbacks

Nếu còn custom provider không dùng nữa, có thể xóa riêng provider đó khỏi config.

Ví dụ với provider woku:

docker exec -it openclaw-gateway \
  node dist/index.js config unset models.providers.woku

Restart:

docker restart openclaw-gateway
Bot trả lời chậm

Tắt thinking mặc định:

docker exec -it openclaw-gateway \
  node dist/index.js config set agents.defaults.thinkingDefault off

docker restart openclaw-gateway

Nếu vẫn chậm, nguyên nhân thường nằm ở model/provider hoặc quota backend, không phải Discord/Telegram.