{"id":13477191,"url":"https://github.com/mbroton/chatgpt-api","last_synced_at":"2025-03-27T04:32:49.824Z","repository":{"id":64269158,"uuid":"574248590","full_name":"mbroton/chatgpt-api","owner":"mbroton","description":"ChatGPT HTTP API Client and CLI","archived":false,"fork":false,"pushed_at":"2022-12-15T11:30:40.000Z","size":76,"stargazers_count":122,"open_issues_count":2,"forks_count":13,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-10-13T15:44:39.287Z","etag":null,"topics":["ai","api","chatgpt","cli","client","http","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mbroton.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-04T21:40:09.000Z","updated_at":"2024-05-10T10:48:04.000Z","dependencies_parsed_at":"2023-01-15T07:30:36.176Z","dependency_job_id":null,"html_url":"https://github.com/mbroton/chatgpt-api","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbroton%2Fchatgpt-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbroton%2Fchatgpt-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbroton%2Fchatgpt-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbroton%2Fchatgpt-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mbroton","download_url":"https://codeload.github.com/mbroton/chatgpt-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222194778,"owners_count":16946984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","api","chatgpt","cli","client","http","python"],"created_at":"2024-07-31T16:01:39.272Z","updated_at":"2025-03-27T04:32:49.806Z","avatar_url":"https://github.com/mbroton.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e💻 ChatGPT API\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003eUnofficial API client and CLI for ChatGPT.\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cimg alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/chatgpt-api\"\u003e\n    \u003cimg alt=\"License\" src=\"https://img.shields.io/github/license/mbroton/chatgpt-api\"\u003e\n    \u003cimg alt=\"Coverage\" src=\"https://img.shields.io/badge/coverage-96%25-green\"\u003e\n\u003c/p\u003e\n\u003cbr\u003e\n\n![Short Demo GIF](https://user-images.githubusercontent.com/50829834/205704349-183b1e73-6e3e-4c91-b537-c51e5cefdf17.gif)\n\n\u003cbr\u003e\n\nThis project is based on `httpx` (uses only HTTP) and uses [Typer (with Rich)](https://typer.tiangolo.com/) for CLI, so responses are looking good (markdown is supported). Also, It has almost 100% code coverage unlike other ChatGPT packages.\n\n![Long Demo GIF](https://user-images.githubusercontent.com/50829834/206066495-2ed2ae06-899a-41df-8d9e-b1dfc048cfaa.gif)\n\n\n## Current status\n\nThis project was created before an API for GPT models existed, and it became deprecated just as quickly as it was developed. The implemented solution has not been operational since the end of 2022.\n\n\n## Installation\n### From Pypi\n```\npip install chatgpt-api\n```\n\n### Source code\n```sh\npip install -r requirements.txt \u0026\u0026 pip install .\n```\n\n## Usage\n\n### As a Command Line Interface\n\n#### Setup\n\nRequired to authenticate. In this step you have to provide a path to the file containing the session key. A simple txt file with the key only is enough.\n```sh\nchatgpt setup\n```\n\n*Tip: Use a file named .session_key in chatgpt-api top directory. It will be ignored by git - see .gitignore.*\n\nThe key will be saved to\n```python\nPath.home() / \".chatgpt_api\" / \"key.txt\"\n```\n\nSession messages are logged to\n```python\nPath.home() / \".chatgpt_api\" / \"logs\"\n```\n\n#### Start chatting\n\n```sh\nchatgpt start\n```\n\n### As an API\n\n`ChatGPT` class inherits from `httpx.Client`\n\nRecommended usage:\n\n```python\nfrom chatgpt.api import ChatGPT\n\nwith ChatGPT(session_token=\"your-session-token\") as chat:\n    response = chat.send_message(\"Hello!\")\n    print(response.content)\n```\n\nWithout context manager you have to explicitly authenticate:\n```python\nfrom chatgpt.api import ChatGPT\n\nchat = ChatGPT(session_token=\"your-session-token\")\nchat.authenticate()\nresponse = chat.send_message(\"Hello!\")\nprint(response.content)\nchat.close()\n```\n\n## How to acquire session key?\n\nAfter you log in to ChatGPT in your browser, get value of `__Secure-next-auth.session-token` cookie. In this project, this is named as a \"session key\".\n\n### Chrome instruction\n\n1. Open ChromeDevTools (F12).\n2. Click on \"Application\" tab.\n3. Click on \"Cookies\", on the left bar.\n4. Copy the value of `__Secure-next-auth.session-token`:\n\n![Cookie value example](https://user-images.githubusercontent.com/50829834/205708256-56f8892d-987d-4ff4-9412-2c23754ecd06.png)\n\nNow, you can use it in CLI or directly from Python code.\n\n## License\n\nDistributed under the MIT License. See `LICENSE` for more information.\n\n## Disclaimer\n\nThis is a personal project, not affiliated in any way with OpenAI. If you have any objections, contact @mbroton.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbroton%2Fchatgpt-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmbroton%2Fchatgpt-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbroton%2Fchatgpt-api/lists"}