How to pass a free LLM API key to a reusable GitHub Actions workflow
Pass the key from the caller job with a named secrets map, declare that same secret ID under the called workflow’s workflow_call trigger, and expose it only to the API request step. Prefer this one-key mapping when a reusable workflow needs one credential. secrets: inherit passes all secrets the caller can access, and a nested workflow needs its own pass-through at the next hop.
Map one key at the call boundary
A reusable workflow is called as a job, so pass the secret beside uses: in the caller file. Keep the caller trigger manual while you verify the wiring:
name: Call the free API smoke test
on:
workflow_dispatch:
jobs:
call-smoke-test:
uses: ./.github/workflows/free-llm-api-smoke.yml
secrets:
chinagenai_key: ${{ secrets.CHINAGENAI_SITE_KEY }}
The called file must opt in to workflow_call and declare the matching ID. The called workflow then maps it into the environment of the one step that sends the request:
name: Free API smoke test
on:
workflow_call:
secrets:
chinagenai_key:
required: true
jobs:
smoke-test:
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- name: Send one small request
env:
LLM_API_KEY: ${{ secrets.chinagenai_key }}
run: |
set -euo pipefail
: "${LLM_API_KEY:?Set CHINAGENAI_SITE_KEY in Actions secrets}"
curl --fail --silent --show-error \
--output "$RUNNER_TEMP/llm-response.json" \
--write-out 'HTTP %{http_code}\n' \
https://chinagenai.com/v1/chat/completions \
-H "Authorization: Bearer ${LLM_API_KEY}" \
-H 'Content-Type: application/json' \
--data '{"model":"free","messages":[{"role":"user","content":"Reply with exactly: workflow-ok"}],"max_tokens":32,"stream":false}'
python3 -c 'import json,os; p=os.path.join(os.environ["RUNNER_TEMP"],"llm-response.json"); print("choices=" + str(len(json.load(open(p)).get("choices", []))))'
Store the actual value as a repository or organization Actions secret named CHINAGENAI_SITE_KEY; the YAML contains only that name. The spelling on the left side of the caller’s map (chinagenai_key) must match the declaration in the called file and the reference inside its job. The source name on the right (CHINAGENAI_SITE_KEY) is the secret stored in the caller’s repository.
This smoke test has no checkout step and needs no repository write access. The guard stops before curl if the value is missing or empty; the log prints the HTTP status and number of returned choices, never the key or response text. Do not turn on shell tracing, print the environment, or upload the response as a workflow artifact. Run it from a trusted branch that can access the secret.
Choose a named map or inheritance
| Caller syntax | What reaches the called workflow | Best fit |
|---|---|---|
| secrets map with chinagenai_key | Only the secret IDs listed in the map. The called workflow declares and consumes the matching ID. | A workflow that needs one API key or a known small set of credentials. |
| secrets: inherit | All organization, repository, and environment secrets the caller can access. GitHub documents this for calls within the same organization or across organizations in the same enterprise. | A trusted internal workflow that intentionally needs the caller’s full secret set. |
The named map makes the handoff visible in a code review: a maintainer can see which credential crosses this boundary without opening the Actions settings page. It also makes reuse easier to audit later. If you add a second credential to the caller repository, it does not silently become part of this workflow’s interface.
Inheritance is shorter YAML, but its access scope is broader. Use it only when the called workflow is trusted to handle every secret available to the caller and the repository relationship supports inheritance. A reusable workflow in another private repository also needs the caller to be allowed by that repository’s Actions access policy. If the caller only needs one API key, a named map is the clearer default.
Pass the key again through nested workflows
Secrets are delivered to the directly called workflow; they do not flow through an entire workflow chain automatically. If workflow A calls B and B calls C, pass the key from A to B and then map it again from B to C:
jobs:
call-next:
uses: ./.github/workflows/send-request.yml
secrets:
chinagenai_key: ${{ secrets.chinagenai_key }}
Use the ID expected by the next file at each boundary. secrets: inherit in A → B does not mean C automatically receives the same values. Check the caller job where a missing key first appears, then follow the map one edge at a time. Keep each called workflow’s GITHUB_TOKEN permissions at the level it needs; nested workflows can keep or reduce token permissions, not raise them.
Diagnose an empty or missing value
Start with names, not values. Compare the secret ID in three places: the caller map, on.workflow_call.secrets in the called file, and the secrets reference in the step. The caller map key and declared ID must be identical, including underscores and capitalization. The right side of the caller map must match the secret name saved in repository or organization settings.
A declaration with required: true catches a missing input at the call boundary, but it does not prove that the stored secret contains a non-empty value. Keep the step-level guard so the job stops before making a request. If the key works in a direct workflow but is empty in a reusable one, check the caller map and any environment attached to the called job. An environment secret is selected by configuring that environment on the called job; when it has the same name as a repository or organization secret, the environment value takes precedence.
For a workflow that calls another workflow, inspect the first edge where the key disappears. If B receives it but C does not, the caller of C inside B needs a secrets map. To reduce accidental exposure during debugging, log only whether the guard passed and the API’s status code. Never print a token prefix, a masked sample, or the entire secret context.
Keep the test separate from untrusted pull requests
A workflow triggered by a pull request from a fork does not get repository secrets. Keep that check unauthenticated. Do not change the trigger to pull_request_target and run fork-controlled code with an API key available. For a one-request API smoke test, workflow_dispatch from a reviewed branch keeps the secret boundary easier to inspect. The GitHub Actions guide for a direct workflow call covers that separate trigger and fork-PR boundary.
A short-lived free test key is useful for a single manual check, not for a recurring schedule or a matrix. Before automating requests, check the provider’s current expiry, quota scope, concurrency rules, and failure counting. A scheduled workflow should use a credential whose documented lifetime and limits match the job.
Common questions
Does required: true reject a blank stored key?
It verifies that the caller passed the declared secret. It does not validate the value stored in GitHub. Keep a non-empty check in the step before the request, and do not echo the value when that check fails.
Can I pass a secret by a different name?
Yes. The caller’s source name can differ from the called workflow’s ID. For example, the repository secret may be CHINAGENAI_SITE_KEY while the reusable workflow accepts chinagenai_key. The identifier on the left of the caller map is the contract that must match the called workflow.
Why does the next reusable workflow lose the key?
Each reusable workflow call is a separate boundary. The workflow that receives the key must explicitly pass it to its own child workflow. Check the map in the job that calls the child, not only the top-level workflow.
Should I use secrets: inherit for a private workflow?
Only if the caller and called repository fit GitHub’s supported organization or enterprise scope and the called workflow should receive every secret available to the caller. For a single API credential, pass that credential by name and verify the called repository’s access policy.
Sources
- GitHub Docs: Reuse workflows (checked November 6, 2026)
- GitHub Docs: Workflow syntax — reusable workflow secrets (checked November 6, 2026)
- GitHub Docs: Using secrets in GitHub Actions
- Stack Overflow: Passing secrets to reusable worflow (question signal only; GitHub documentation is the technical source)