Skip to main content
query() requires authentication configuration to start a session. The recommended approach is to use a Personal Access Token (PAT) injected via environment variables, ideal for scripts, CI, and host application integration. If you have already logged in locally via qodercli, you can also reuse the existing credentials.

Generating a PAT

Generate a Personal Access Token at qoder.com/account/integrations:
  1. Sign in to your Qoder account
  2. Open Account → Integrations
  3. Create a new PAT, picking expiry and scopes as needed
  4. Copy it immediately — the value cannot be retrieved again after the page is closed; if lost, you must regenerate
A single account can hold multiple PATs. Issuing separate tokens per environment (local scripts, CI, production) makes per-token revocation possible.

Reading PAT from the Default Environment Variable

The default environment variable name is QODER_PERSONAL_ACCESS_TOKEN.

Reading PAT from a Custom Environment Variable

Equivalent explicit form:
If the same-named variable is set in both options.env and process.env, the SDK reads the value from options.env first.

Passing the PAT Directly

If your host application has already obtained a PAT from a secrets management service, existing credentials, or backend API, you can pass it directly. Do not hard-code token literals in source code.

Reusing qodercli Login Session

If you have already completed login via qodercli on the local machine, you can let the SDK delegate to the CLI to read the existing credentials. This method works well in interactive local environments and is not recommended for stateless CI.

API Overview

Error Handling

Missing auth Configuration

query() will throw auth_not_configured before starting:

Environment Variable Not Set

When using { envVar } but the variable is empty, the SDK will throw auth_access_token_env_var_not_configured:

Authentication Failure During Execution

When the remote rejects the token, the token expires, or the CLI exits with an auth error, use onAuthExpired to trigger a re-login or token refresh flow:
The SDK does not automatically refresh PATs. The host application should create a new query() session with a new auth configuration after obtaining a new token.

Best Practices

  • In production and CI, prefer environment variables or secrets management services; never hard-code tokens.
  • Do not write tokens to logs, error objects, or debug output.
  • For automated environments, use PATs rather than relying on local qodercli login session.
  • For user-facing applications, register onAuthExpired to convert authentication failures into clear sign-in prompts.
  • When rotating tokens, create a new query session; do not reuse a session that has already failed authentication.