Skip to content

OpenCodeConsoleProvider

Namespace: E2E.OAuth

public sealed class OpenCodeConsoleProvider : IOAuthProvider

OpenCode Zen and Go through an OpenCode Console sign-in. Console speaks RFC 8628 device authorization; approving the code binds the login to one workspace, and its token is a bearer for both the Console API and inference. Refresh tokens rotate. The workspace config says which models are served and over which protocol: Zen is its opencode provider, Go opencode-go. Go ids take a go/ prefix here.

Inheritance: object

Implements: IOAuthProvider

View source

OpenCodeConsoleProvider(HttpClient?, string)

Section titled “OpenCodeConsoleProvider(HttpClient?, string)”
public OpenCodeConsoleProvider(HttpClient? http = null, string consoleUrl = "https://opencode.ai/console")

Parameters

Name Type Description
http HttpClient Sends the login’s own requests. Unset, a shared client.
consoleUrl string Test seam.

View source

public const string DefaultConsoleUrl = "https://opencode.ai/console"

Value: string

View source

public const string GoPrefix = "go/"

Value: string

View source

public const string InferenceUrl = "https://opencode.ai/inference"

Value: string

View source

public string? ApiKeyEnv { get; }

The variable whose API key the provider’s calls and model list read in place of the stored login.

Value: string

View source

public string Id { get; }

The id in the credentials file and on the command line: openai, github-copilot, opencode-console, spacexai.

Value: string

View source

public string Name { get; }

The vendor’s name for messages.

Value: string

View source

ListModelsAsync(HttpClient, CancellationToken)

Section titled “ListModelsAsync(HttpClient, CancellationToken)”
public Task<IReadOnlyList<SubscriptionModel>> ListModelsAsync(HttpClient http, CancellationToken cancellationToken)

Leaves out disabled models and Zen’s free ones, which only OpenCode’s own clients may use.

Parameters

Name Type Description
http HttpClient
cancellationToken CancellationToken

Returns: Task<IReadOnlyList<SubscriptionModel>>

View source

LoginAsync(OAuthLoginCallbacks, OAuthLoginOptions, CancellationToken)

Section titled “LoginAsync(OAuthLoginCallbacks, OAuthLoginOptions, CancellationToken)”
public Task<OAuthCredentials> LoginAsync(OAuthLoginCallbacks callbacks, OAuthLoginOptions options, CancellationToken cancellationToken)

Parameters

Name Type Description
callbacks OAuthLoginCallbacks
options OAuthLoginOptions
cancellationToken CancellationToken

Returns: Task<OAuthCredentials>

View source

PrepareAsync(HttpRequestMessage, OAuthCredentials, CancellationToken)

Section titled “PrepareAsync(HttpRequestMessage, OAuthCredentials, CancellationToken)”
public Task PrepareAsync(HttpRequestMessage request, OAuthCredentials credentials, CancellationToken cancellationToken)

Names the workspace as each API expects it.

Parameters

Name Type Description
request HttpRequestMessage
credentials OAuthCredentials
cancellationToken CancellationToken

Returns: Task

View source

RefreshAsync(OAuthCredentials, CancellationToken)

Section titled “RefreshAsync(OAuthCredentials, CancellationToken)”
public Task<OAuthCredentials> RefreshAsync(OAuthCredentials credentials, CancellationToken cancellationToken)

Renews the credentials, or throws LoginRequired when the user has to sign in again.

Parameters

Name Type Description
credentials OAuthCredentials
cancellationToken CancellationToken

Returns: Task<OAuthCredentials>

View source