Login to xAI via SuperGrok / X Subscription OAuth Without API Key

Introduction

When using the xai route of llm-pi-ai in DeepSeek Harness (DSH), the common approach is to apply for an xAI API key yourself and then write it into an environment variable or credentials configuration. For developers who already hold a SuperGrok or X Premium subscription and want to call Grok directly with their subscription identity, maintaining an extra API key is unnecessary and easily gets disconnected from the subscription account.

Below we introduce the community plugin dsh-xai-oauth (maintainer tonylee2022): it completes xAI device-code (RFC 8628) authorization on the DSH Web side, injects the access token into the DSH credential XAI_OAUTH_TOKEN, and automatically refreshes it when it is about to expire, so that the xai provider can resolve a valid token on every request.

What Is This

dsh-xai-oauth is an admin-security plugin for DSH; its current npm package version is 0.1.5, licensed under MIT. It does not wrap the Grok model; it is only responsible for OAuth login, token persistence and renewal, and it uses a bundle patch to make the xai route of llm-pi-ai use apiKeyEnv: XAI_OAUTH_TOKEN.

Repository: https://github.com/tonylee2022/dsh-xai-oauth
Community directory page: https://www.skillhub.cn/plugins/tonylee2022/dsh-xai-oauth (an independent site, with no official affiliation with DeepSeek / High-Flyer)

Core Features

  1. Device-code authorization: requests a device code from https://auth.x.ai/oauth2/device/code; the client id and scope (including grok-cli:access and api:access) are consistent with xAI CLI / pi-ai.
  2. Polling for token exchange: polls https://auth.x.ai/oauth2/token; after the user approves, the access token and refresh token are obtained and atomically written to $DSH_HOME/xai-oauth.json (file permissions 0600, directory 0700).
  3. Credential injection: writes the current access token into XAI_OAUTH_TOKEN via ctx.credentials; patches the xai route of llm-pi-ai with apiKeyEnv: XAI_OAUTH_TOKEN, resolving the latest value at request time.
  4. Automatic renewal: checks once every 60 seconds; when less than 5 minutes remain until expiration, it renews using the refresh token and writes it back.

The Web UI provides an xAI (Grok/X) settings page next to Settings → Model Providers: log in to xAI → copy the user code → open the authorization page and approve on the official xAI page → authorization completes automatically.

Installation and Activation

The plugin targets the web profile; after installation you need to restart the web profile (dsh --profile web).

Install from npm (recommended):

dsh plugin --profile web add dsh-xai-oauth

Or install from GitHub:

dsh plugin --profile web add github:tonylee2022/dsh-xai-oauth

Local source installation (for development/debugging):

dsh plugin --profile web add ./dsh-xai-oauth

Before installing, it is recommended to review the repository source code and the MIT license yourself; the plugin runs with the permissions of the current dsh process, and the token will be stored in a file on the host side.

Typical Usage

  1. Run any of the installation commands above.
  2. Restart: dsh --profile web.
  3. In the Web UI, go to Settings → Model Providers, enter xAI (Grok/X), and click “Log in to xAI”.
  4. Copy the user code shown on the interface, click “Open authorization page”, and log in and approve on the official xAI page using your SuperGrok or X Premium account.
  5. After authorization completes, just select a model route that uses the xai provider in DSH as usual; there is no need to configure an xAI API key again.

Optional configuration (written into the plugin’s config):

- id: xai-oauth
  config:
    path: /secure/path/xai-oauth.json   # defaults to $DSH_HOME/xai-oauth.json
    controlPort: 1457                    # local status service port

Compatibility and Security Boundaries

Compatibility

  • dsh web / regular browser: the page origin is http://127.0.0.1:<port>.
  • DSH Desktop 0.2.1 and later: the Web UI loads from dsh-app://app; the plugin accepts that origin starting from 0.1.5. Earlier DSH versions may encounter a CORS preflight failure during login, manifesting as “Failed to fetch” in the interface.

Security boundaries

  • The token is stored only in an owner-only file on the host side; the Web page does not directly touch the token.
  • The local control service listens only on 127.0.0.1:1457 and accepts only local DSH Web origins (http://127.0.0.1:*, http://localhost:*, http://[::1]:*, and Desktop’s dsh-app://app); logout requests carry a CSRF token.
  • The access token is equivalent to an API credential for that subscription; do not leak it or commit it to a version repository.

Use Cases and Notes

It is suitable for developers who already have a SuperGrok or X Premium subscription on the xAI side and want to go through OAuth uniformly in DSH instead of managing an API key themselves. It is not suitable for environments that require independent billing for enterprise-level API quotas, or that cannot complete device-code authorization in a browser.

The DSH ecosystem emphasizes “everything is a plugin”; when choosing community plugins, verify behavior based on the README and source code, and do not assume a binding relationship between the directory site and official products.

Conclusion

dsh-xai-oauth strings together xAI subscription OAuth, token renewal, and XAI_OAUTH_TOKEN injection into a reproducible path, reducing the credential-maintenance cost of using Grok in DSH. For more information, visit the SkillHub directory page or the GitHub repository README.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye