@takutakahashi/codex-agentapi
v1.4.0
Published
coder/agentapi compatible HTTP API server using @openai/codex-sdk
Downloads
573
Maintainers
Readme
codex-agentapi
coder/agentapi compatible HTTP API server using @openai/codex-sdk
Features
- ✅ Full coder/agentapi compatibility - Implements the standard agent API specification
- 🤖 OpenAI Codex SDK integration - Powered by @openai/codex-sdk
- 🔌 MCP servers support - Full Model Context Protocol server configuration
- 🎨 Claude Code Skills - Integrates with Claude Code plugin system
- 📡 Real-time updates - Server-Sent Events (SSE) for streaming responses
- 📄 Message pagination - Multiple pagination strategies (limit, around, cursor-based)
- 🎯 TypeScript - Strict type checking throughout
- 🧪 Well-tested - Comprehensive test coverage with Vitest
Installation
npm install -g @takutakahashi/codex-agentapiOr with Bun:
bun install -g @takutakahashi/codex-agentapiQuick Start
1. Set up environment variables
Create a .env file:
OPENAI_API_KEY=your-api-key-here
PORT=9000
HOST=localhost
LOG_LEVEL=info2. (Optional) Configure MCP servers and Skills
Create .claude/config.json:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"],
"env": {}
}
},
"plugins": {
"example-skill": {
"enabled": true,
"config": {}
}
}
}3. Start the server
codex-agentapiOr for development:
bun run devThe server will start at http://localhost:9000.
API Endpoints
Health Check
GET /healthReturns server health status.
Agent Status
GET /statusReturns the current agent status (running or stable).
Send Message
POST /message
Content-Type: application/json
{
"content": "Fix the bug in main.ts",
"type": "user"
}Sends a message to the agent. Returns immediately while processing continues asynchronously.
Get Messages
GET /messages?limit=10&direction=tailRetrieves conversation messages with pagination support, including tool result messages.
Pagination options:
limit+direction(head/tail): Get first/last N messagesaround+context: Get messages around a specific IDafter/before: Cursor-based pagination
Tool Status
GET /tool_statusReturns currently active tool executions.
Server-Sent Events
GET /eventsSubscribe to real-time updates via SSE.
Event types:
message: New user/assistant messagetool_start: Tool execution startedtool_end: Tool execution completedstatus_change: Agent status changedturn_completed: Turn finished with usage infoerror: Error occurred
Actions
GET /actionGet pending actions (questions, plans).
POST /action
Content-Type: application/json
{
"type": "stop_agent"
}Send action response (answer question, approve plan, stop agent).
Configuration
Environment Variables
| Variable | Default | Description |
|----------|---------|-------------|
| OPENAI_API_KEY | - | OpenAI API key (required) |
| PORT | 9000 | Server port |
| HOST | localhost | Server host |
| WORKING_DIRECTORY | . | Agent working directory |
| LOG_LEVEL | info | Log level (debug/info/warn/error) |
Claude Config
The server reads .claude/config.json from:
- Current working directory:
./.claude/config.json - Home directory:
~/.claude/config.json
Development
Prerequisites
- Node.js 18+
- Bun (recommended) or npm
Install dependencies
bun installRun in development mode
bun run devBuild
bun run buildRun tests
bun testRun tests with coverage
bun run test:coverageLint
bun run lintArchitecture
codex-agentapi/
├── src/
│ ├── app/ # App wiring (server + main)
│ ├── http/ # HTTP layer (routes + validation)
│ ├── application/ # Use cases / domain services
│ ├── infrastructure/ # Adapters (MCP/skills/Codex config)
│ ├── shared/ # Cross-cutting concerns
│ └── types/ # TypeScript types
└── bin/
└── cli.js # CLI entry pointDifferences from claude-agentapi
| Feature | claude-agentapi | codex-agentapi | |---------|----------------|----------------| | Agent SDK | @anthropic-ai/claude-agent-sdk | @openai/codex-sdk | | Provider | AWS Bedrock / Anthropic API | OpenAI Codex | | Runtime | Node.js/Bun | Bun (recommended) |
Publishing
This package is automatically published to npm when a new release is created on GitHub.
Steps to publish a new version:
Create and push a tag:
git tag v1.0.0 git push origin v1.0.0Create a GitHub Release:
gh release create v1.0.0 --title "v1.0.0" --notes "Release notes here"Automated workflow:
- GitHub Actions will automatically:
- Update
package.jsonversion - Run tests and build
- Publish to npm
- Update release notes
- Update
- GitHub Actions will automatically:
Manual publish (if needed):
npm login
npm publish --access publicLicense
MIT
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
