How to use a free LLM API in GitHub Actions

Yes. Store the API key as a GitHub Actions secret, expose it only to the step that needs it, and start with a manually triggered workflow on a trusted branch. Do not put the key in YAML, commit it, print it, or pass it to code from a forked pull request. ChinaGenAI's /connect page describes 48-hour keys with up to 20 attempts per network or verified account per UTC day, so use this sample for a short smoke test, not as a dependable scheduled CI credential.

Add one repository secret

In the repository, open Settings → Secrets and variables → Actions → New repository secret. Name it CHINAGENAI_SITE_KEY, paste the site key, and save. The value is not part of the workflow file. GitHub only makes a secret available when the workflow explicitly references it; mapping it to one step's environment keeps its scope narrower than setting it for every job.

Run a manual smoke test

Save this as .github/workflows/test-free-llm-api.yml, then add it to the repository's default branch. The Run workflow control appears only after the workflow file exists on that branch. The job does not check out code or request write permissions because it only sends one API request.

name: Test free LLM API

on:
  workflow_dispatch:

permissions:
  contents: read

jobs:
  smoke-test:
    runs-on: ubuntu-latest
    timeout-minutes: 2
    steps:
      - name: Send one small request
        env:
          LLM_API_KEY: ${{ secrets.CHINAGENAI_SITE_KEY }}
        run: |
          set -euo pipefail
          : "${LLM_API_KEY:?Add CHINAGENAI_SITE_KEY in repository 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; d=json.load(open(os.path.join(os.environ["RUNNER_TEMP"],"llm-response.json"))); print("choices=" + str(len(d.get("choices", []))))'

The HTTP code and choices count are enough to confirm the request completed; the workflow does not print the key or the model's response. The small max_tokens value keeps this check short. Never add set -x, echo "$LLM_API_KEY", or a command that uploads the secret in an artifact.

Keep fork pull requests outside the secret path

A workflow triggered by a fork's pull_request does not receive repository secrets (apart from GitHub's restricted GITHUB_TOKEN). That is an intentional boundary. Do not switch to pull_request_target and then check out or run the fork's code with a provider key available: a changed test, package script, or dependency can read its process environment and send the key away.

For this one-call check, workflow_dispatch is simpler: run it from a reviewed branch that you control. If a separate pull-request check is needed, keep it secret-free and test code without authenticated API calls. Do not try to work around GitHub's fork protections.

Flow diagram showing a repository Actions secret passed to one trusted manual workflow step, with fork pull requests kept outside the secret path.

Fit the credential to the job

The example uses ChinaGenAI's OpenAI-compatible endpoint and the documented free model alias. On the site's connection page checked on November 6, 2026, test keys were described as valid for 48 hours, limited to 20 attempts per network or verified account per UTC day, limited to one active request per key and two across the site, and counted when a request is accepted even if the upstream call fails. That makes a manual smoke test reasonable; a daily workflow, matrix, or retry loop can exhaust the allowance or outlive the key.

For recurring CI, use a provider credential whose current lifetime and quota fit that workload. Confirm the provider's rules for model, account, project and billing before scheduling calls. “Free” does not mean permanent availability or a guaranteed request budget.

Decision diagram matching a short-lived demo key to one manual smoke test and a recurring CI job to a credential with a suitable documented lifetime and quota.

Check the result without spending extra attempts

  1. Start with one manual run on the default branch; the workflow does not need a checkout step.
  2. If the job has no secret, confirm the exact secret name and that repository Actions are enabled.
  3. If the response is unauthorized, replace an expired or revoked demo key; do not print it to debug the workflow.
  4. If the request is rate-limited, stop retries and check the provider's current quota scope and reset window.
  5. Remove the temporary secret when the smoke test is over, or rotate it if it may have appeared in a log, artifact, cache, or shell trace.

Common questions

Why is the secret empty in a fork pull-request job?

GitHub withholds repository secrets from workflows triggered by fork pull requests. Keep those checks unauthenticated; run the API smoke test manually from a trusted branch instead.

Why is “Run workflow” missing?

The workflow must be present on the repository's default branch for the manual trigger to be available. Check the filename under .github/workflows/ and the branch selected in the Actions page.

Can I schedule this demo key every day?

No. A 48-hour key and a per-network daily attempt allowance are not a durable CI credential. Use an appropriately scoped provider key for a recurring workflow and recheck its documented limits before enabling a schedule.

Reusable workflow variant

If this smoke test lives in a reusable workflow, pass the secret by name at the caller boundary and declare the matching workflow_call secret in the called file. See the reusable workflow secret handoff guide for the caller/callee YAML, inheritance scope, and nested workflow checks.

Sources