การยืนยันตัวตน
วิธี Sign In ของ OpenAI
Codex รองรับการ sign in หลักสองวิธีสำหรับการใช้โมเดลของ OpenAI:
- Sign in with ChatGPT สำหรับการเข้าถึงผ่าน subscription
- Sign in with an API key สำหรับการเข้าถึงแบบ usage-based
Codex บน Cloud ต้องใช้การ sign in ด้วย ChatGPT ในขณะที่ CLI และ IDE extension รองรับทั้งสองวิธี วิธีที่เลือกจะกำหนดนโยบาย admin controls และ data policies ที่บังคับใช้
Sign in with ChatGPT
เมื่อ sign in ผ่าน Codex app, CLI หรือ IDE Extension ระบบจะเปิดหน้าต่างเบราว์เซอร์เพื่อทำ authentication จากนั้นเบราว์เซอร์จะส่ง access token กลับมาที่ client
หากสภาพแวดล้อมของคุณมี token อยู่แล้ว สามารถส่งผ่าน stdin ได้:
printenv CODEX_ACCESS_TOKEN | codex login --with-access-token
Sign in with an API key
API keys หาได้จาก OpenAI dashboard การใช้งานจะถูกเรียกเก็บเงินผ่าน OpenAI Platform account ตามอัตรา API มาตรฐาน
การยืนยันตัวตนด้วย API key ช่วยให้ทำงานแบบ local ได้ แต่จำกัดฟีเจอร์บางอย่างที่ต้องการ ChatGPT workspace access วิธีนี้เหมาะที่สุดสำหรับงาน CI/CD แบบ programmatic และแนะนำให้ใช้แทนการ sign in ด้วย ChatGPT สำหรับงาน automation
Enterprise Access Tokens
Admin ของ ChatGPT Enterprise workspace สามารถให้สิทธิ์สมาชิกสร้าง Codex access tokens สำหรับ workflow แบบ automated ที่ไม่ต้อง interactive ในขณะที่ยังคงรักษา workspace access และ controls ไว้
คำแนะนำด้านความปลอดภัย
เปิดใช้งาน multi-factor authentication (MFA) เพื่อรักษาความปลอดภัย Codex cloud account ของคุณ เนื่องจากมีการเข้าถึง codebase โดยตรง
การ Cache ข้อมูล Login
Codex จะ cache credentials ไว้ใน ~/.codex/auth.json หรือ OS credential store Credentials จะถูกแชร์ระหว่าง CLI และ IDE Extension; การ logout จากที่ใดที่หนึ่งจะล้าง session ออก
ตั้งค่าตำแหน่งเก็บ credential:
cli_auth_credentials_store = "keyring" # หรือ "file" หรือ "auto"
การยืนยันตัวตนบนอุปกรณ์แบบ Headless
สำหรับสภาพแวดล้อม remote หรือ headless ให้ใช้ device code authentication (beta) โดยรัน:
codex login --device-auth
หากไม่ได้ผล ให้ copy cached credentials จากเครื่องที่ผ่านการยืนยันตัวตนแล้ว
ผู้ให้บริการโมเดลทางเลือก
Custom model providers สามารถยืนยันตัวตนผ่าน:
- OpenAI authentication — ตั้งค่า
requires_openai_auth = true - Environment variables — ตั้งค่า
env_key = "<ENV_VARIABLE_NAME>" - ไม่ต้อง authentication — สำหรับโมเดล local