Documentation Index
Fetch the complete documentation index at: https://docs.qoder.com/llms.txt
Use this file to discover all available pages before exploring further.
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:- Sign in to your Qoder account
- Open Account → Integrations
- Create a new PAT, picking expiry and scopes as needed
- 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.
Recommended Usage
Reading PAT from the Default Environment Variable
The default environment variable name isQODER_PERSONAL_ACCESS_TOKEN.
Reading PAT from a Custom Environment Variable
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 viaqodercli 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
| Option | Purpose |
|---|---|
accessTokenFromEnv() | Read PAT from QODER_PERSONAL_ACCESS_TOKEN. |
accessTokenFromEnv(envVar) | Read PAT from a specified environment variable. |
accessToken(token) | Use a PAT already obtained by the caller. |
qodercliAuth() | Reuse the local qodercli login session. |
onAuthExpired | Callback when the token expires, authentication fails, or the CLI exits with an auth error. Fires at most once per query session. |
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, useonAuthExpired to trigger a re-login or token refresh flow:
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
qoderclilogin session. - For user-facing applications, register
onAuthExpiredto 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.