Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,12 @@ See [Protecting your `OPENAI_API_KEY`](./docs/security.md#protecting-your-openai

## Outputs

| Name | Description |
| --------------- | --------------------------------------- |
| `final-message` | Final message returned by `codex exec`. |
| Name | Description |
| --------------------- | ----------------------------------------------------------------------------- |
| `final-message` | Final message returned by `codex exec`. |
| `input-tokens` | Total input tokens consumed by the run (empty string if unavailable). |
| `output-tokens` | Total output tokens consumed by the run (empty string if unavailable). |
| `cached-input-tokens` | Total cached input tokens consumed by the run (empty string if unavailable). |

As we saw in the example above, we took the `final-message` output of the `run_codex` step and made it an output of the `codex` job in the workflow:

Expand All @@ -148,6 +151,45 @@ jobs:
final_message: ${{ steps.run_codex.outputs.final-message }}
```

### Using token outputs

Log token usage or enforce a budget in a downstream step:

```yaml
- uses: openai/codex-action@v1
id: codex
with:
prompt: "Fix the failing tests"
openai-api-key: ${{ secrets.OPENAI_API_KEY }}

- name: Log token usage
run: |
echo "Input tokens: ${{ steps.codex.outputs.input-tokens }}"
echo "Output tokens: ${{ steps.codex.outputs.output-tokens }}"
echo "Cached tokens: ${{ steps.codex.outputs.cached-input-tokens }}"
```

To track costs across runs, forward the token counts to a cost dashboard.
[AgentMeter](https://agentmeter.app) is a GitHub-native option built for this:

```yaml
- uses: openai/codex-action@v1
id: codex
with:
prompt: "..."
openai-api-key: ${{ secrets.OPENAI_API_KEY }}

- uses: AgentMeter/agentmeter-action@v1
with:
api_key: ${{ secrets.AGENTMETER_API_KEY }}
model: gpt-5.3-codex
engine: codex
input_tokens: ${{ steps.codex.outputs.input-tokens }}
output_tokens: ${{ steps.codex.outputs.output-tokens }}
cache_read_tokens: ${{ steps.codex.outputs.cached-input-tokens }}
status: ${{ job.status }}
```

## Additional tips

- Run this action after `actions/checkout@v5` so Codex has access to your repository contents.
Expand Down
20 changes: 20 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ outputs:
final-message:
description: "Raw output emitted by `codex exec`."
value: ${{ steps.run_codex.outputs['final-message'] }}
input-tokens:
description: "Total input tokens consumed by the Codex run (empty if unavailable)."
value: ${{ steps.extract_tokens.outputs['input-tokens'] }}
output-tokens:
description: "Total output tokens consumed by the Codex run (empty if unavailable)."
value: ${{ steps.extract_tokens.outputs['output-tokens'] }}
cached-input-tokens:
description: "Total cached input tokens consumed by the Codex run (empty if unavailable)."
value: ${{ steps.extract_tokens.outputs['cached-input-tokens'] }}
runs:
using: "composite"
steps:
Expand Down Expand Up @@ -349,3 +358,14 @@ runs:
--effort "$CODEX_EFFORT" \
--safety-strategy "$CODEX_SAFETY_STRATEGY" \
--codex-user "$CODEX_USER"

- name: Extract token outputs
id: extract_tokens
if: ${{ inputs.prompt != '' || inputs['prompt-file'] != '' }}
env:
ACTION_PATH: ${{ github.action_path }}
CODEX_HOME: ${{ steps.resolve_home.outputs.codex-home }}
shell: bash
run: |
node "$ACTION_PATH/dist/main.js" extract-token-outputs \
--codex-home "$CODEX_HOME"
Loading
Loading