A developer can configure OpenCode on a personal workstation in a few minutes. The situation becomes more complicated when the same AI coding workflow needs to run inside a shared development environment, automated pipeline, or company-managed server.
Consider a team that uses OpenCode to review pull requests, generate test cases, inspect application dependencies, and explain failed builds. During development, each engineer may authenticate through an individual account. Once these workflows move into CI/CD, however, personal authentication introduces operational problems.
What happens when an employee leaves the company? Should a build pipeline continue using an engineer's personal API key? How can administrators distinguish automated model consumption from individual development usage? What happens when a credential expires during a scheduled deployment?
These are not simply authentication questions. They are part of API governance.
OpenCode Console provides both personal API keys and service account keys. Understanding the difference is important when moving from individual experimentation to repeatable engineering workflows.
This guide explains how to structure OpenCode authentication for automated workloads, manage permissions, isolate credentials, and connect different model providers through a consistent API configuration.
1. Why Personal API Keys Become a Problem in CI/CD
Personal API keys are convenient for individual developers.
A developer creates a key, stores it in an environment variable, and uses it to authenticate requests. This works well when one person owns the entire workflow.
A shared environment has different requirements.
For example, imagine a development team with five engineers. Each engineer works on a separate branch, but the company also operates a central pipeline that runs automated code reviews.
If the pipeline uses one developer's personal key, several problems can emerge:
- Usage is associated with an individual rather than the automated service.
- Changes to that employee's workspace permissions may affect the pipeline.
- Credential rotation requires coordination with the employee.
- Usage reports become harder to interpret.
- Multiple projects may unknowingly share the same credential.
This structure creates unnecessary operational dependencies.
A production pipeline should have an identity that belongs to the workload itself.
That is the purpose of a service account.
2. Personal API Keys vs. Service Account API Keys
OpenCode Console supports two types of API keys.
| Attribute | Personal API Key | Service Account API Key |
|---|---|---|
| Owner | Individual workspace member | Non-human service account |
| Creation | Account settings | Workspace administration |
| Usage attribution | Individual member | Service account |
| Budget relationship | Member budget | Service account budget |
| Typical application | Personal scripts | CI/CD and shared automation |
| Administration | Individual user | Workspace owner or administrator |
A personal key acts with the permissions of the member who created it.
A service account has its own identity, API keys, usage records, and budget. Workspace owners and administrators manage these accounts.
This separation makes service accounts more suitable for shared workloads.
There is another important detail: an API key does not automatically grant unrestricted access. Its permissions remain limited by the identity and permission level associated with that key.
For example, a key configured with read-only model permissions may list available models but cannot submit inference requests.
That distinction matters when diagnosing an apparently valid credential that still cannot call a model.
3. Create a Dedicated Identity for Each Automated Workload
Avoid creating one service account for every application in the company.
A more manageable structure separates workloads by purpose.
For example:
| Service account | Responsibility |
|---|---|
| ci-code-review | Automated pull request analysis |
| test-generation | Unit test generation |
| documentation-agent | Documentation maintenance |
| release-assistant | Release notes and change summaries |
This organization provides several advantages.
First, administrators can identify which application consumes model resources.
Second, a credential can be disabled without unnecessarily interrupting unrelated services.
Third, different applications can receive different permission levels and budget limits.
For a small project, a single service account may be sufficient. As the number of automated workflows increases, separate identities become easier to manage.
4. Create and Configure an OpenCode Service Account
The general configuration process is straightforward.
- Open the OpenCode Console workspace.
- Navigate to Settings.
- Find Service accounts.
- Create a new service account.
- Give it a descriptive name.
- Open the newly created account.
- Generate an API key.
- Configure the required expiration and permissions.
- Copy the key and store it securely.
OpenCode displays the complete key only when it is created. Afterward, the Console shows its prefix rather than the full secret.
This means the original value should be transferred directly into a secure secret store.
Do not put the key into a source-code repository or a shared configuration file.
5. Store Credentials in Environment Variables
A simple local example looks like this:
A production pipeline should retrieve the secret from its CI/CD secret manager.
For example, a generic deployment configuration might use:
This example only verifies that the secret is available to the job. It does not establish that the key has model-request permissions or that an inference endpoint is correctly configured.
Those checks should be performed separately.
A useful rule is to distinguish three independent conditions:
- The credential exists.
- The credential has sufficient permissions.
- The configured endpoint accepts the credential.
A successful check of the first condition does not prove the other two.
6. Verify API Access Before Running a Pipeline
Before connecting an AI coding workflow, test the Console API directly.
For example, OpenCode documents a model-listing endpoint:
A successful response helps establish that the service can authenticate the request and access the model-listing endpoint.
However, model discovery and inference are different operations.
A read-only credential may be able to list models but not call them. A restricted key needs the appropriate model-request permission.
Check the permission configuration before interpreting a failed inference request as a network problem.
Also record the following information:
- HTTP response status.
- Request timestamp.
- Target endpoint.
- Model identifier.
- Credential identity.
- Response request ID, if provided.
Never include the full API key in diagnostic logs.
7. Using an API Gateway for Multiple Model Backends
Automated coding workflows rarely remain tied to one model forever.
A team may use one model for routine code explanations, another for complex debugging, and a third for documentation or test generation.
Managing independent endpoints and credentials across multiple pipelines introduces configuration overhead.
An API gateway provides another architectural option.
Instead of placing separate provider configurations throughout the application, developers can centralize the model endpoint and authentication layer.
For example, a compatible OpenAI SDK integration can be structured as follows:
The important point is that the API key, base URL, and model ID are configuration values rather than hardcoded application dependencies.
A gateway such as 4SAPI can provide a centralized API entry point for compatible model integrations. Developers should still verify the supported protocol and model identifier for their selected workflow.
A gateway does not replace OpenCode's own service-account permissions. These are separate authentication and access-control layers.
8. Credential Rotation Without Breaking Automation
Credential rotation should be treated as a planned deployment operation.
A practical rotation sequence is:
- Generate a replacement service account key.
- Add it to the CI/CD secret manager.
- Test the replacement in a controlled pipeline.
- Switch production jobs to the new secret.
- Verify successful model requests.
- Revoke the previous key.
Do not revoke the existing credential before testing its replacement.
This sequence avoids unnecessary interruptions.
For systems with several deployment environments, use a staged rollout. Development and staging should validate the replacement before production adopts it.
9. Common Problems and How to Diagnose Them
| Symptom | Possible cause | Recommended check |
|---|---|---|
| 401 Unauthorized | Invalid or expired key | Check the issuing workspace and key |
| 403 Forbidden | Insufficient permissions | Review key access settings |
| Model listing succeeds but inference fails | Read-only permission | Check model-request access |
| CI job cannot find the key | Secret not injected | Inspect pipeline environment configuration |
| Requests use unexpected budget | Personal identity used | Check the credential owner |
| One project works but another fails | Different workspace or permissions | Compare endpoint and workspace configuration |
One mistake worth avoiding is treating every authentication failure as an expired key.
The service may be rejecting the request because of permissions, workspace association, or an incorrect endpoint.
The distinction is important because generating another key will not fix a configuration problem.
10. Production Checklist
Before deploying an automated OpenCode workflow, verify:
- Each shared workload has an appropriate service identity.
- API keys are stored in a secret manager.
- Permissions follow the principle of least privilege.
- Model identifiers are explicitly configured.
- Usage can be attributed to the correct workload.
- Credential rotation has been tested.
- Failed requests are logged without exposing secrets.
- Model availability and endpoint compatibility are checked independently.
Conclusion
Moving OpenCode from a personal development environment into CI/CD changes the authentication requirements.
Personal API keys remain useful for individual experimentation, but shared automation needs clearer ownership, usage attribution, and credential lifecycle management.
Service accounts provide a dedicated identity for these workloads. When combined with restricted permissions, centralized secret storage, and controlled credential rotation, they make automated model access easier to operate.
For teams building multi-model applications, the next architectural step is to separate the application identity from the model-provider connection. This allows authentication, usage governance, and model routing to evolve without rewriting every application.
References and further reading
- OpenCode Console API Documentation
- OpenCode Console Models
- OpenCode Harness Configuration
- OpenCode API Documentation
- OpenAI API Authentication Documentation
- OWASP Secrets Management Cheat Sheet
Related articles




