codex provides a very nice api, accessible by running “codex app-server”: