npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@grikomsn/ai-sdk-provider-chatgpt-oauth

v2.0.2

Published

Vercel AI SDK v7 provider for OpenAI models through ChatGPT OAuth

Readme

ChatGPT OAuth Provider for AI SDK 7

An ESM-only Vercel AI SDK v7 provider for using models available to a ChatGPT account through Codex OAuth.

This community provider uses ChatGPT's Codex backend rather than the public OpenAI API. The endpoint and available models can change without notice. Review the limitations before using it in production.

Features

  • Native AI SDK 7 ProviderV4 and LanguageModelV4 implementation
  • Text generation, reasoning summaries, streaming, usage, and tool-call events
  • PKCE OAuth, automatic token refresh, environment variables, or Codex CLI credentials
  • Live model catalog lookup, including the exact instructions required by each model
  • Zod 3.25.76+ and Zod 4.1.8+ compatibility
  • Node.js 22+, ESM-only package

Install

npm install ai@7 @grikomsn/ai-sdk-provider-chatgpt-oauth

Authenticate

The quickest option is to sign in with the Codex CLI:

npm install --global @openai/codex
codex login

The provider reads ~/.codex/auth.json by default. It also supports:

  • A standalone PKCE OAuth example
  • CHATGPT_OAUTH_ACCESS_TOKEN, CHATGPT_OAUTH_ACCOUNT_ID, and optional CHATGPT_OAUTH_REFRESH_TOKEN environment variables
  • Direct credentials
  • A custom AuthProvider

Never commit OAuth tokens or Codex authentication files.

Generate Text

import { generateText } from 'ai';
import { createChatGPTOAuth } from '@grikomsn/ai-sdk-provider-chatgpt-oauth';

const chatgpt = createChatGPTOAuth();

const result = await generateText({
  model: chatgpt('gpt-5.5'),
  prompt: 'Write a haiku about TypeScript.',
});

console.log(result.text);
console.log(result.usage);

Stream Text

import { streamText } from 'ai';
import { createChatGPTOAuth } from '@grikomsn/ai-sdk-provider-chatgpt-oauth';

const result = streamText({
  model: createChatGPTOAuth()('gpt-5.5'),
  prompt: 'Explain OAuth PKCE in three short paragraphs.',
});

for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}

Provider Registry

The provider implements the complete AI SDK 7 ProviderV4 registry contract:

import { createProviderRegistry } from 'ai';
import { createChatGPTOAuth } from '@grikomsn/ai-sdk-provider-chatgpt-oauth';

const registry = createProviderRegistry({
  chatgpt: createChatGPTOAuth(),
});

const model = registry.languageModel('chatgpt:gpt-5.5');

Only language models are available. Registry requests for embedding or image models throw AI SDK's NoSuchModelError.

Reasoning

Use AI SDK 7's call-level reasoning option:

const result = await generateText({
  model: chatgpt('gpt-5.5'),
  reasoning: 'high',
  prompt: 'Analyze this concurrency bug.',
});

Provider defaults can also be configured per provider or model:

const chatgpt = createChatGPTOAuth({
  reasoningEffort: 'medium',
  reasoningSummary: 'auto',
});

const model = chatgpt('gpt-5.5', {
  reasoningEffort: 'xhigh',
});

See the reasoning options.

Tools

This provider currently maps command tools to the Codex shell tool and planning tools to update_plan. Other custom function tools are returned as unsupported warnings.

import { generateText, tool } from 'ai';
import { z } from 'zod';

const result = await generateText({
  model: chatgpt('gpt-5.5'),
  prompt: 'List TypeScript files in the current directory.',
  tools: {
    shell: tool({
      description: 'Run a command',
      inputSchema: z.object({
        command: z.array(z.string()),
      }),
      execute: async ({ command }) => runSandboxed(command),
    }),
  },
});

Only execute model-provided commands inside an appropriate sandbox. See tool calling.

Models

The provider fetches /codex/models for the authenticated account and caches the selected model's required instructions. It therefore follows account entitlements instead of maintaining a permanently hard-coded allowlist.

Verified on July 3, 2026:

| Model | Context window | Live verification | | -------------- | -------------: | ----------------------------- | | gpt-5.5 | 372,000 | Text generation and streaming | | gpt-5.4 | 272,000 | Text generation | | gpt-5.4-mini | 272,000 | Catalog availability |

Other IDs are accepted by the TypeScript API, but calls fail with MODEL_NOT_AVAILABLE when the account catalog does not contain them.

Configuration

| Option | Type | Description | | ------------------ | -------------------------- | ----------------------------------------------------------- | | baseURL | string | API base URL; defaults to https://chatgpt.com/backend-api | | headers | Record<string, string> | Additional request headers | | fetch | FetchFunction | Custom fetch implementation | | credentials | ChatGPTOAuthCredentials | Direct OAuth credentials | | credentialsPath | string | Codex auth path; defaults to ~/.codex/auth.json | | authProvider | AuthProvider | Custom credential source | | autoRefresh | boolean | Refresh expiring credentials; defaults to true | | reasoningEffort | ReasoningEffort \| null | Default reasoning effort | | reasoningSummary | ReasoningSummary \| null | Default reasoning summary | | instructions | string | Override catalog instructions for custom backends |

Unsupported Settings

The Codex backend currently ignores or rejects several standard language-model settings. The provider emits AI SDK warnings for temperature, topP, and maxOutputTokens. Structured output APIs are not supported; use text generation, parse the result, and validate it in application code.

See the limitations and JSON formatting guides.

Errors

import { ChatGPTOAuthError } from '@grikomsn/ai-sdk-provider-chatgpt-oauth';

try {
  await generateText({
    model: chatgpt('gpt-5.5'),
    prompt: 'Hello',
  });
} catch (error) {
  if (error instanceof ChatGPTOAuthError) {
    console.error(error.code, error.statusCode, error.message);
  }
}

Development

npm ci
npm run check
npm run test:coverage

npm run check verifies formatting, lint, library and example typechecking, deterministic unit/integration tests, the package build, and the exact tarball contents. Live OAuth verification is separate:

cd oauth-example
npm install
CHATGPT_OAUTH_BROWSER=Safari npm run login
npm test

Changesets manages versions and changelog entries. Add a changeset with npm run changeset in every pull request that changes the published package. Merging the automated release pull request publishes through npm trusted publishing; the workflow stores no npm token.

Report security issues privately as described in SECURITY.md.

Ownership

This maintained fork uses the @grikomsn package scope and lives at grikomsn/ai-sdk-provider-chatgpt-oauth. The original work by Ben Vargas remains credited in the package metadata and license.

License

MIT