- Read: 8 min
- Updated: July 10, 2026
- Audience: Platform engineers
§ 01 Choose the right integration
Use Apex CLI or MCP when a person or coding agent is working in a repository. Use the service API when a headless process needs HTTP, JSON, and a static organization credential.
The machine-readable contract is available at
/api/apex/v1/openapi.json.
§ 02 Prerequisites
- Connect the GitHub repository and link it to an active workspace in the same Apex organization that owns the service key.
- Use a full 40- or 64-character Git commit SHA. Branch names and moving refs are not accepted.
- Create or revoke keys as an Apex organization manager or Bedrock administrator.
- Store the key in a secret manager. Apex displays the raw secret only once and stores only its hash.
Version-one repository support The first service API release accepts GitHub repositories already connected to your Apex organization. GitLab service-account access will follow once connection ownership can be made explicit.
§ 03 Create a service key
--company <id-or-handle> to skip that prompt, or when a non-interactive command cannot prompt. Copy the secret into your secret manager when it is created. It cannot be retrieved later.
When --scope is omitted, the key gets all three scopes: scans:create, scans:read, and findings:read. List metadata or revoke a key without exposing its secret:
§ 04 Trigger a scan
Send a unique, stableIdempotency-Key for each intended scan. Reuse that same value when retrying the same request.
Apex reuses the active workspace already linked to the repository. If more than one workspace matches, include its workspaceId in the body. The service API never creates or rewrites workspaces.
Paths are focus hints
The optional paths array prioritizes those files in Apex prompts, but it is not a hard repository boundary. The scan may inspect or report code outside those paths. Omit it if you do not need focus hints; version one does not yet provide strict path isolation.
A successful request returns HTTP 202:
§ 05 Poll scan status
- Start - Treat the HTTP 202 response as queued and retain its scanId.
- Poll - Use bounded exponential backoff while status is queued or running.
- Stop - Stop polling on completed, failed, or cancelled.
- Collect - Fetch findings after the scan reaches completed.
§ 06 Fetch findings
Findings access includes drafts
A key with findings:read can retrieve unpublished draft findings for scans in its organization so an external hub can perform triage. Treat the service key as a privileged credential and do not expose its findings payload to users who cannot review drafts in Apex.
The first request after a scan completes durably synchronizes the terminal finding set. If that sync is unavailable or has more pages, Apex returns 503 with Retry-After. Retry the same GET; after readiness is persisted, later requests serve the cached report without depending on Kernel.
§ 07 Errors and retries
Retry safely GET requests are safe to retry. After a transport error, timeout, or5xx, retry POST only with the original body and the originalIdempotency-Key. Idempotency is organization-scoped, so replay remains safe if the service key is rotated between attempts. A definitive4xxresponse is retained: after correcting its precondition, submit it as a new intended scan with a newIdempotency-Key. Never log the Authorization or X-API-Key header.
§ 08 Claude and Codex prompts
These prompts work in Claude Code or Codex. The first keeps key creation in your own terminal; the others ask the agent to use the service API for the headless runtime rather than trying to run MCP inside a serverless function.- Give me the exact Apex CLI command I should run in my own terminal to create a service key named Audit hub. Do not run it for me or ask me to paste the secret into this chat.
- Using APEX_SERVICE_KEY from the environment, write a serverless TypeScript adapter that starts an Apex scan for this repository and commit. Send a stable Idempotency-Key, poll until terminal, and return the GitLab SAST findings.
- Add Apex to our audit hub. Call POST /api/apex/v1/scans, poll GET
/api/apex/v1/scans/{scanId}with bounded backoff, then fetch /findings. Never log the bearer token and retry only safe requests. - Given an Apex scanId for a scan started in the web app, fetch its GitLab SAST findings with APEX_SERVICE_KEY, preserve the raw response, and import each vulnerability once by stable ID. Do not trigger another scan or log the credential.
- Diagnose this Apex API response without printing secrets. Explain whether it is a transport/5xx retry that must preserve the original Idempotency-Key, or a definitive 4xx that must be corrected and submitted as a new intended scan with a new key.