Skip to content

API access

OpenCode Go API keys and base URLs

Configure an OpenCode Go API key with the correct Go base URL, OpenAI, Anthropic, and Gemini endpoints, session header, and error handling.

A sculptural dark authentication key connected to glowing circuit paths

The short answer

Use a Go-scoped Console API key with the base URL https://opencode.ai/inference/go. OpenAI, Anthropic, and Gemini paths are served through that base, and coding-agent requests must preserve a stable session ID.

Where do you create an OpenCode Go API key?

Create a personal key under Account and Personal API keys in OpenCode Console, or use a service account key for shared systems and CI.

  1. 01

    Open the Console account menu.

  2. 02

    Choose Personal API keys and select Add API key.

  3. 03

    Pick the workspace that has the active Go subscription.

  4. 04

    Name the key for the client or environment that will use it.

  5. 05

    Create the key and copy it immediately because the full value is shown only once.

Use a separate key for each durable environment. A laptop, a CI runner, and a shared internal tool should not intentionally share one personal credential.

For shared machines or automation, ask a workspace owner or admin about a service account key so usage is not tied to one person.

What is the OpenCode Go base URL?

The Go base URL is https://opencode.ai/inference/go. Do not use the pay-as-you-go base URL when your requests should draw from a Go subscription.

OpenCode Console base URLs
Billing pathBase URL
Pay as you gohttps://opencode.ai/inference
Go subscriptionhttps://opencode.ai/inference/go
Append the path for the API dialect your client speaks.

Using the wrong base URL can produce an authentication or entitlement error even when the key itself is valid. Confirm the host and the /go segment before debugging the model ID.

Which API endpoints does OpenCode Go serve?

OpenCode translates requests between common API dialects, so a text model can usually be called through OpenAI Responses, Chat Completions, Anthropic Messages, or Gemini request formats.

Paths appended to the Go base URL
APIPath
OpenAI Responses/openai/v1/responses
OpenAI Chat Completions/openai/v1/chat/completions
Anthropic Messages/anthropic/v1/messages
Gemini generateContent/google/v1beta/models/<model>:generateContent

The model catalog recommends a native API for each model, but that recommendation does not restrict the other text APIs. Translation is useful when an existing application already speaks one provider format.

Why do Go requests need a session ID?

A stable session identifier helps Console route a conversation consistently and reuse cached prompt context. Go requires it for coding-agent chat traffic.

Generic clients can send x-opencode-session with one stable value per conversation. OpenCode, Claude Code, Codex, Hermes, Pi, and several other agents have native headers that Console can recognize.

If a proxy reconstructs requests, verify that it preserves the native session header or adds x-opencode-session intentionally. Dropping the header can reduce routing consistency and prompt-cache reuse even if the request otherwise succeeds.

How do you discover models and check usage?

The public model endpoint lists current IDs and metadata. The authenticated usage endpoint reports the rolling, weekly, and monthly allowance meters.

List available Go models
curl https://opencode.ai/inference/go/v1/models
Check the current key usage
curl https://opencode.ai/inference/go/v1/usage \
  -H "Authorization: Bearer $OPENCODE_API_KEY"

Fetch the model list at startup or on a scheduled refresh instead of hard-coding a catalog that can change. Keep the usage endpoint on the server when possible so the key never reaches the browser.

How should you protect an OpenCode Go API key?

Treat the key like any other production credential: keep it server-side, scope usage to a known client, rotate on exposure, and inspect HTTP errors before replacing it.

  • Store the key in a runtime secret store, not in Git or a NEXT_PUBLIC environment variable.
  • Use separate keys for local development, CI, and production when the provider supports it.
  • Log model IDs and request correlation data without logging Authorization headers.
  • Return generic client errors while retaining the provider status code in private server logs.
  • Rotate the key immediately if it appears in a browser bundle, public issue, screenshot, or shell history.

Why is the API key not working?

Check the workspace entitlement, billing base URL, model ID, and session header before assuming the credential is invalid.

Common OpenCode Go API failures
SymptomFirst check
HTTP 401Missing, malformed, revoked, or wrong-environment key
HTTP 403No Go entitlement or model not covered by the key
Wrong billing pathUse /inference/go, not /inference
Poor cache reusePreserve a stable session ID across the conversation
Unknown modelRefresh the public model catalog and use the current ID

Primary sources

Verify the current details

Product availability, model limits, pricing, and data terms can change. These primary sources are the authority for the facts on this page.

Next step

Start with an active Go workspace

Choose Go for standard usage or Go Plus when long coding sessions need more included capacity.