Codex SDK
Codex CLI, IDE 확장, Codex Web으로 Codex를 사용하고 있다면 프로그래밍 방식으로도 Codex를 제어할 수 있습니다.
다음이 필요할 때 SDK를 사용합니다.
- CI/CD 파이프라인의 일부로 Codex를 제어합니다.
- Codex와 상호작용해 복잡한 엔지니어링 작업을 수행하는 자체 에이전트를 만듭니다.
- 내부 도구와 워크플로에 Codex를 통합합니다.
- 자체 애플리케이션 안에서 Codex를 사용합니다.
TypeScript 라이브러리
TypeScript 라이브러리는 애플리케이션 안에서 Codex를 제어하는 방법을 제공하며, 비대화형 모드보다 더 포괄적이고 유연합니다.
이 라이브러리는 서버 측에서 사용합니다. Node.js 18 이상이 필요합니다.
설치
시작하려면 npm으로 Codex SDK를 설치합니다.
npm install @openai/codex-sdk
사용법
Codex로 스레드를 시작하고 프롬프트를 실행합니다.
const codex = new Codex();
const thread = codex.startThread();
const result = await thread.run(
"Make a plan to diagnose and fix the CI failures"
);
console.log(result);
같은 스레드에서 계속하려면 run()을 다시 호출합니다. 이전 스레드를 이어가려면 스레드 ID를 제공합니다.
// running the same thread
const result = await thread.run("Implement the plan");
console.log(result);
// resuming past thread
const threadId = "{thread-id}";
const thread2 = codex.resumeThread(threadId);
const result2 = await thread2.run("Pick up where you left off");
console.log(result2);
자세한 내용은 TypeScript 저장소를 참고하십시오.
Python 라이브러리
Python SDK는 실험적 기능이며 JSON-RPC를 통해 로컬 Codex app-server를 제어합니다. Python 3.10 이상과 오픈 소스 Codex 저장소의 로컬 checkout이 필요합니다.
설치
Codex 저장소 루트에서 SDK를 editable 모드로 설치합니다.
cd sdk/python
python -m pip install -e .
로컬 SDK를 직접 사용할 때는 AppServerConfig(codex_bin=...)를 전달해 로컬 codex 바이너리를 지정하거나, 저장소의 예제와 노트북 bootstrap을 사용합니다.
사용법
Codex를 시작하고, 스레드를 만들고, 프롬프트를 실행합니다.
from codex_app_server import Codex
with Codex() as codex:
thread = codex.thread_start(model="gpt-5.4")
result = thread.run("Make a plan to diagnose and fix the CI failures")
print(result.final_response)
애플리케이션이 이미 비동기 방식이라면 AsyncCodex를 사용합니다.
import asyncio
from codex_app_server import AsyncCodex
async def main() -> None:
async with AsyncCodex() as codex:
thread = await codex.thread_start(model="gpt-5.4")
result = await thread.run("Implement the plan")
print(result.final_response)
asyncio.run(main())
자세한 내용은 Python 저장소를 참고하십시오.