---
title: "GitHub Actions"
subtitle: "Give a GitHub Actions job a one-hour Respan API key from its OIDC token, so your repository stores no Respan key."
---

A GitHub Actions job can call Respan without a `RESPAN_API_KEY` secret. The job sends its GitHub OIDC token to Respan, which checks it against your project's trust rules and returns a temporary API key that expires after one hour. Use it for CI jobs that call the gateway or the Respan API.

## Set it up

<Steps>
<Step title="Trust your repository">

Create a trust rule for the repository, once, with your usual Respan API key. The keys a rule hands out have full access to the project, so the key you create it with needs all four [permissions](/docs/documentation/admin/respan-api-keys#create-a-key) (**Read**, **Write**, **Gateway**, and **Admin**) and no IP allowlist. From the dashboard, only project admins can manage trust rules.

```bash
curl https://api.respan.ai/api/integrations/github-actions/trust-rules/ \
  -H "Authorization: Bearer $RESPAN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "repository": "acme/api",
    "ref": "refs/heads/main",
    "environment": "production"
  }'
```

| Field | Description |
| --- | --- |
| `repository` | The exact `owner/repo`. No wildcards. Stored in lowercase, because GitHub names are case-insensitive. |
| `ref` | Optional. The exact git ref the job must run on, such as `refs/heads/main` or `refs/tags/v1.2.0`. Leave it out or send `null` to accept any branch or tag. |
| `environment` | Optional. The GitHub environment the job must run in. Leave it out or send `null` to accept any job. |
| `is_active` | Optional. `true` by default. An inactive rule hands out no keys. |

An empty string for `ref` or `environment` is rejected.

</Step>
<Step title="Copy your project ID">

Go to **Settings** › **General** and click the **Project ID** to copy it.

</Step>
<Step title="Get a key in your workflow">

Give the job the `id-token: write` permission. Request a GitHub OIDC token with the audience `respan`, then exchange it at `POST https://api.respan.ai/api/integrations/github-actions/token/` with your project ID. The exchange needs no Respan key: the token is the credential.

```yaml .github/workflows/respan.yml
name: Call Respan

on: push

permissions:
  id-token: write   # lets the job request a GitHub OIDC token
  contents: read

jobs:
  call-respan:
    runs-on: ubuntu-latest
    steps:
      - name: Get a Respan API key
        run: |
          github_token=$(curl -sSf \
            -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
            "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=respan" | jq -r .value)

          api_key=$(curl -sSf https://api.respan.ai/api/integrations/github-actions/token/ \
            -H "Content-Type: application/json" \
            -d "{\"token\": \"$github_token\", \"project_id\": \"YOUR_PROJECT_ID\"}" \
            | jq -r .api_key)

          echo "::add-mask::$api_key"
          echo "RESPAN_API_KEY=$api_key" >> "$GITHUB_ENV"

      - name: Call the gateway
        run: |
          curl -sSf https://api.respan.ai/api/chat/completions \
            -H "Authorization: Bearer $RESPAN_API_KEY" \
            -H "Content-Type: application/json" \
            -d '{"model": "gpt-5.5", "messages": [{"role": "user", "content": "Hello"}]}'
```

The exchange takes `token` (the raw GitHub OIDC token) and `project_id`, and returns `api_key` and `expires_at`. Later steps use `RESPAN_API_KEY` like any other key, with the SDKs or the API.

<img src={"/docs/images/admin/github-actions-run-light.png"} className="block dark:hidden" alt="A GitHub Actions job with every step green, including Get a Respan API key" />
<img src={"/docs/images/admin/github-actions-run-dark.png"} className="hidden dark:block" alt="A GitHub Actions job with every step green, including Get a Respan API key" />

</Step>
</Steps>

<Warning>
Anyone who can run a workflow in the trusted repository can get a key, including from a pull request branch when the rule accepts every ref. Set `ref` or `environment` when people you don't trust can push to the repository.
</Warning>

## The key

- It has full access to the project, like a key with every permission.
- It expires one hour after the exchange. Get a new one in each job.
- It shows in your API keys list with the **Temporary** tag, named after the repository, ref, and run, such as `github:acme/api@refs/heads/main run 1234567890`.

<img src={"/docs/images/admin/github-actions-temporary-key-light.png"} className="block dark:hidden" alt="The API keys list with keys named github:respanai/respan-example-projects, each tagged Temporary" />
<img src={"/docs/images/admin/github-actions-temporary-key-dark.png"} className="hidden dark:block" alt="The API keys list with keys named github:respanai/respan-example-projects, each tagged Temporary" />

## Manage trust rules

`GET https://api.respan.ai/api/integrations/github-actions/trust-rules/` lists your project's rules, newest first. `DELETE https://api.respan.ai/api/integrations/github-actions/trust-rules/{id}/` stops trusting a repository: its jobs get no new keys from then on, and keys already handed out expire within the hour. Both need a key with the **Admin** permission.

## When the exchange is refused

| Status | Cause | Fix |
| --- | --- | --- |
| `400` | `token` or `project_id` is missing. | Send both. |
| `401` | The token has the wrong audience. | Request it with `audience=respan`. |
| `401` | The token has expired. | Request it in the same job, right before the exchange. |
| `401` | The token is invalid, or wasn't issued by GitHub Actions. | Send the raw `value` from the token request, unchanged. |
| `403` | No active trust rule of the project matches the token. | Check the rule's `repository`, `ref`, and `environment` against the job, and that `project_id` is the project with the rule. |
| `503` | Respan couldn't reach GitHub to verify the token. | Retry. |

Each client IP can call the exchange 30 times a minute.
