grok

package
v0.32.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package grok turns a SuperGrok / X Premium+ subscription into a memcode backend via xAI's OAuth device-code flow. Unlike the claude/codex/copilot sources, there is no other tool's login to reuse: memcode runs the login itself (accounts.x.ai device code, the flow the grok CLI client is registered for) and owns the token file. The resulting bearer token drives api.x.ai/v1 through the shared Grok Responses adapter unchanged.

Consent-gated upstream like every subscription source: it activates only when the user explicitly selects the grok source, and the login itself is an interactive approval in the user's browser.

Index

Constants

View Source
const (

	// BaseURL is the xAI inference host the subscription token is valid for.
	BaseURL = "https://api.x.ai/v1"
)

Variables

View Source
var ErrTierGated = errors.New("this xAI account's subscription tier is not allowed API access over OAuth — set XAI_API_KEY instead, or upgrade at x.ai/grok")

ErrTierGated marks a 403 from the token endpoint: the OAuth grant is valid but xAI's backend does not allow API access for this subscription tier. Re-logging in won't change it; the fix is an XAI_API_KEY or a higher tier.

Functions

func Available

func Available() bool

Available reports whether a Grok login is stored, for the wizard's menu (no parse, no network).

func Login

func Login(ctx context.Context, prompt func(verificationURL, userCode string)) error

Login runs the device-code flow: it requests a code, hands the verification URL and user code to prompt (which shows them and may open a browser), polls until the user approves, and stores the tokens. Blocking; ctx cancels it.

func Logout

func Logout() error

Logout removes the stored login.

func Resolve

func Resolve() (string, error)

Resolve returns a live access token, refreshing it first when it is close to expiry. An error explains the fix (run `memcode auth use grok`).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL