展示HN:使用ChatGPT帐户免费访问OpenAI API
Show HN: Free OpenAI API Access with ChatGPT Account

原始链接: https://github.com/EvanZhouDev/openai-oauth

## 通过ChatGPT账户访问OpenAI API:openai-oauth `openai-oauth`是一个社区维护的工具,允许您使用现有的ChatGPT账户身份验证来免费访问OpenAI的API。它通过利用OAuth令牌绕过对API密钥的需求。 **工作原理:** * **CLI & 代理:** 运行 `npx openai-oauth` 以启动一个本地代理(默认:http://127.0.0.1:10531/v1),该代理与OpenAI API兼容。 * **Vercel AI SDK 提供商:** 直接与Vercel AI SDK集成,以便在应用程序中无缝使用。 * **模型:** 访问通过您的ChatGPT账户可用的Codex模型(例如,gpt-5.4)。 **主要特性:** 支持 `/v1/responses`、`/v1/chat/completions`、`/v1/models`、流式传输、toolcalls和推理跟踪。 **重要注意事项:** 这是一个*非官方*项目。请小心保管您的 `auth.json` 文件(包含登录凭据)——就像密码一样。它仅用于**个人、本地实验**,不提供任何保证。用户有完全责任遵守OpenAI的服务条款。

Hacker News 新闻 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Show HN: 使用 ChatGPT 账户免费访问 OpenAI API (github.com/evanzhoudev) 4 分,EvanZhouDev 发表于 2 小时前 | 隐藏 | 过去 | 收藏 | 2 条评论 帮助 redgridtactical 发表于 1 小时前 | 下一个 [–] 我觉得这会很快失效。OpenAI 会注意到通过该 Codex 端点的不匹配使用模式的流量并将其锁定。 回复 EvanZhouDev 发表于 1 小时前 | 父评论 | 下一个 [–] 我相信 OpenAI 在某种程度上允许了这种使用方式(见:OpenCode、OpenClaw 具有内置的 OpenAI OAuth)。这只是将其开放给其他开发者! 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

NPM | Legal

Free OpenAI API access with your ChatGPT account.

Just run npx openai-oauth.

You can currently use openai-oauth in two different ways:

This package lets you create a localhost proxy to chatgpt.com/backend-api/codex/responses pre-authenticated with your Oauth tokens.

Use directly:

npx openai-oauth

OpenAI-compatible endpoint ready at http://127.0.0.1:10531/v1
Use this as your OpenAI base URL. No API key is required.
Available Models: gpt-5.4, gpt-5.3-codex, ...

This is a Vercel AI SDK Provider.

import { generateText } from "ai";
import { createOpenAIOAuth } from "openai-oauth-provider";

const openai = createOpenAIOAuth();

const result = await generateText({
	model: openai("gpt-5.4"),
	prompt: "write an essay about dogs",
});

console.log(result.text);

The CLI and the provider share the same core OAuth transport settings.

Config CLI Provider Default Description
Host binding --host N/A 127.0.0.1 Host interface the local proxy binds to.
Port --port N/A 10531 Port the local proxy binds to.
Model allowlist --models N/A Account-specific Codex models discovered from ChatGPT Comma-separated list of model ids exposed by /v1/models. When omitted, the CLI discovers the models your account has access to.
Codex API version --codex-version codexVersion Local codex --version, then @openai/codex latest from npm, then 0.111.0 Override the Codex API client version used for model discovery.
Upstream base URL --base-url baseURL https://chatgpt.com/backend-api/codex Override the upstream Codex base URL.
OAuth client id --oauth-client-id clientId app_EMoamEEZ73f0CkXaXp7hrann Override the OAuth client id used for refresh.
OAuth token URL --oauth-token-url tokenUrl https://auth.openai.com/oauth/token Override the OAuth token URL used for refresh.
Auth file path --oauth-file authFilePath --oauth-file path if provided, otherwise $CHATGPT_LOCAL_HOME/auth.json, $CODEX_HOME/auth.json, ~/.chatgpt-local/auth.json, ~/.codex/auth.json Override where the local OAuth auth file is discovered.
Ensure fresh tokens N/A ensureFresh true Control whether access tokens are refreshed automatically.
Provider name N/A name openai Override the provider name exposed to Vercel AI SDK internals.

What currently works:

  • Working Endpoints:
    • /v1/responses
    • /v1/chat/completions
    • /v1/models (account-aware by default, or overridden with --models)
  • Streaming Responses
  • Toolcalls
  • Reasoning Traces

What is intentionally not there yet:

  • Only LLMs supported by Codex are available. This lists updates over time and is dependent on your Codex plan.
  • Login flow is intentionally not bundled. Simply run npx @openai/codex login to create the auth file.
  • There is no stateful replay support on the CLI /v1/responses endpoint. The proxy is stateless and expects callers to send the full conversation history.

OpenAI's Codex CLI uses a special endpoint at chatgpt.com/backend-api/codex/responses to let you use special OpenAI rate limits tied to your ChatGPT account.

By using the same Oauth tokens as Codex, we can effectively use OpenAI's API through Oauth instead of buying API credits.

  • packages/openai-oauth-core Private shared transport, auth refresh, SSE helpers, and replay state.
  • packages/openai-oauth-provider Public Vercel AI SDK provider that talks directly to Codex using local auth files.
  • packages/openai-oauth Public CLI and localhost proxy package intended for npx openai-oauth.

This is an unofficial, community-maintained project and is not affiliated with, endorsed by, or sponsored by OpenAI, Inc.

It uses your local Codex/ChatGPT authentication cache (auth.json, e.g. ~/.codex/auth.json) and should be treated like password-equivalent credentials.

Use only for personal, local experimentation on trusted machines; do not run as a hosted service, do not share access, and do not pool or redistribute tokens.

You are solely responsible for complying with OpenAI’s Terms, policies, and any applicable agreements; misuse may result in rate limits, suspension, or termination.

Provided “as is” with no warranties; you assume all risk for data exposure, costs, and account actions.

联系我们 contact @ memedata.com