Skip to content

Login with ChatGPT

The login-with-chatgpt command allows you to authenticate with the Cosine CLI using your existing ChatGPT subscription. This feature enables direct routing to OpenAI’s Codex models, billing usage through your existing OpenAI account.

This authentication method works with:

  • Personal subscriptions: ChatGPT Plus and ChatGPT Pro
  • Organization subscriptions: ChatGPT Business and ChatGPT Enterprise

Run the command and let it automatically open your browser:

Terminal window
cos login-with-chatgpt
  1. Your browser will open to the OpenAI OAuth authorization page
  2. Sign in with your OpenAI account (or select your organization)
  3. Authorize Cosine CLI to access your account
  4. You’ll be redirected back to confirm successful authentication

If you prefer not to open a browser automatically or are in a headless environment:

Terminal window
cos login-with-chatgpt --no-browser
  1. The CLI will display a URL for you to open manually
  2. Complete the OAuth flow in your browser
  3. Copy the final redirect URL from your browser’s address bar
  4. Paste it back into the CLI prompt

When you authenticate with login-with-chatgpt:

  1. OAuth PKCE Flow: The CLI uses the OAuth 2.0 Authorization Code flow with PKCE for secure authentication
  2. Token Storage: Your access token, refresh token, and account ID are securely stored in ~/.cosine/auth.openai.json with 0600 permissions
  3. Automatic Refresh: When your access token nears expiration, the CLI automatically refreshes it using your refresh token
  4. Direct Inference: Future cos commands use your OpenAI OAuth token for direct inference to OpenAI’s Codex models

After login, your configuration is automatically updated:

[auth.openai]
auth_method = "oauth"
[config]
logged_in_with_openai = true

The CLI supports multiple authentication methods. To switch between them:

  • Cosine Account: Use cos login to authenticate with your Cosine account
  • ChatGPT Subscription: Use cos login-with-chatgpt to use your OpenAI subscription

If you see this error when running commands:

no OpenAI OAuth tokens found; run 'cos login-with-chatgpt'

Run the login command again to refresh your authentication.

If your OpenAI OAuth tokens expire or become invalid, the CLI will automatically:

  1. Display a warning message in the logs
  2. Disable OpenAI OAuth authentication
  3. Fall back to the default Cosine inference endpoint
  4. Continue working without crashing

You can re-enable OpenAI OAuth by running:

Terminal window
cos login-with-chatgpt

If you encounter a “state mismatch” error during the manual flow:

  • Ensure you complete the OAuth flow promptly (state expires after 10 minutes)
  • Copy the complete redirect URL including all query parameters
  • Try the browser flow instead if issues persist

If token refresh fails:

  • Re-run cos login-with-chatgpt to obtain fresh tokens
  • Check your network connection
  • Verify your OpenAI subscription is active
  • Tokens are stored with file permissions 0600 (readable only by your user)
  • PKCE (Proof Key for Code Exchange) protects against authorization code interception attacks
  • State parameters prevent CSRF attacks
  • No credentials are ever logged or transmitted to Cosine servers when using this auth method