> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getspine.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Codex CLI

> Use OpenAI Codex CLI with the Spine API for research and deliverables.

[Codex CLI](https://github.com/openai/codex) is OpenAI's terminal-based coding agent. Give it a system prompt that includes Spine's API pattern and it will delegate research-heavy tasks to Spine.

## Install

Download the system-prompt snippet:

```bash theme={"theme":{"light":"github-light","dark":"tokyo-night"}}
curl -o spine-codex-prompt.md \
  https://docs.getspine.ai/static/agent-files/spine.codex.md
```

<Card title="Download system prompt" icon="download" href="/static/agent-files/spine.codex.md">
  `spine.codex.md` — append to your Codex system prompt or project instructions
</Card>

Then append it to your Codex system instructions, or paste it into your project's `AGENTS.md`.

## Set your API key

```bash theme={"theme":{"light":"github-light","dark":"tokyo-night"}}
export SPINE_API_KEY="sk_spine_..."
```

Create a key at [platform.getspine.ai/keys](https://platform.getspine.ai/keys).

## What it does

The system prompt teaches Codex:

1. **When** to call Spine — multi-source research, deliverable generation, competitive analyses
2. **The two-step pattern** — `POST /v1/run` → poll `GET /v1/run/{run_id}`
3. **How to pick a template** based on the deliverable type
4. **How to present results** — `final_output` text + artifact download links

## Non-interactive / CI usage

Three one-time setup steps are required for unattended Codex invocation:

```bash theme={"theme":{"light":"github-light","dark":"tokyo-night"}}
# 1. Register your OpenAI API key with Codex. The OPENAI_API_KEY env var
#    alone is not sufficient — Codex stores auth in its own keychain.
printenv OPENAI_API_KEY | codex login --with-api-key

# 2. Export your Spine key in the same shell Codex will run in.
export SPINE_API_KEY=sk_spine_...

# 3. (Optional) confirm Codex auth status:
codex login status
```

Then invoke:

```bash theme={"theme":{"light":"github-light","dark":"tokyo-night"}}
codex exec \
  --json --skip-git-repo-check \
  --dangerously-bypass-approvals-and-sandbox \
  "Produce a deep-research memo on <topic> using Spine" \
  < /dev/null
```

<Note>
  * `--skip-git-repo-check` is required when running outside a git repo; without it Codex refuses with `Not inside a trusted directory`.
  * `--full-auto` is tempting for automation but its sandbox blocks network — Codex cannot reach `api.getspine.ai` under that preset. Use `--dangerously-bypass-approvals-and-sandbox` or a custom sandbox policy that allows outbound HTTPS.
  * `< /dev/null` closes stdin; without it `codex exec` blocks waiting for additional input even when the prompt is passed as an argument.
</Note>

## Example

```
You: Create a market analysis of European fintech APIs and output as a slide deck

Codex: I'll use the Spine API with template=slides.

  curl -X POST https://api.getspine.ai/v1/run \
    -H "X-API-KEY: $SPINE_API_KEY" \
    -F "prompt=Market analysis of European fintech APIs" \
    -F "template=slides"

  [polling... completed in 14m 32s]

  Results:
  - European_Fintech_APIs.pptx → https://...
  - Credits consumed: 41
```

<Note>
  For long-running production workflows, register a webhook instead of polling — see [Webhooks](/api-reference/concepts/webhooks). Poll loops inside `codex exec` can exceed the turn budget for runs longer than 5–10 minutes.
</Note>
