{"id":13585132,"url":"https://github.com/Erol444/gpt4-openai-api","last_synced_at":"2025-04-07T06:32:41.425Z","repository":{"id":164167226,"uuid":"637492065","full_name":"Erol444/gpt4-openai-api","owner":"Erol444","description":"Python package that provides (unofficial) API access to the GPT-4 through chat.openai.com. Works with langchain. Supports search DALL-E 3, plugins, continuing generation.","archived":false,"fork":false,"pushed_at":"2025-03-04T11:11:13.000Z","size":41,"stargazers_count":172,"open_issues_count":10,"forks_count":39,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-05T12:01:39.569Z","etag":null,"topics":["api","browsing","chatgpt","dall-e-3","gpt4","langchain","llm","openai","plugins","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Erol444.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-07T18:07:22.000Z","updated_at":"2025-03-31T07:51:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"510aa1b3-08f9-4896-b700-d122927c70cc","html_url":"https://github.com/Erol444/gpt4-openai-api","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Erol444%2Fgpt4-openai-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Erol444%2Fgpt4-openai-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Erol444%2Fgpt4-openai-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Erol444%2Fgpt4-openai-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Erol444","download_url":"https://codeload.github.com/Erol444/gpt4-openai-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247607550,"owners_count":20965942,"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":["api","browsing","chatgpt","dall-e-3","gpt4","langchain","llm","openai","plugins","python"],"created_at":"2024-08-01T15:04:45.419Z","updated_at":"2025-04-07T06:32:41.419Z","avatar_url":"https://github.com/Erol444.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# GPT4 OpenAI unofficial API\n\n## Unofficial GPT-4 API access via chat.openai.com using Selenium\n\n\u003e ⚠️ **Note** To use hosted **API for GPT4o Search** we recommend using [Apify actor](https://apify.com/openapi/gpt-search-private-api), as it's hosted, more stable, and faster. **Price**: $10/1000 answers.\n\n#### Selenium-based API\n\nHave you **applied to GPT-4 API access** but **OpenAI is too busy to reply**? Me too, that's why I created this package. It uses [selenium webdriver](https://www.selenium.dev/) to emulate user interaction on [chat.openai.com](chat.openai.com). If the account has `ChatGPT Plus`, the driver **will use GPT-4**, otherwise it will use the default GPT-3.5.\n\nIt supports both **GPT4 browser, DALL-E 3, and plugins** by selecting model via `GPT4OpenAI(token=token, model='gpt-4')`, or `model='gpt-4-plugins'`.\n\n**Note:** This unofficial API library is not endorsed by OpenAI and violates their Terms of Service. Use it at your own risk; the creator assumes no liability for any consequences. Please adhere to platform's ToS and exercise caution with unofficial resources.\n\nThe core logic was taken from the [IntelligenzaArtificiale/Free-Auto-GPT](https://github.com/IntelligenzaArtificiale/Free-Auto-GPT).\n\n## Demo\n\n[![Demo GIF](https://github.com/Erol444/gpt4-openai-api/assets/18037362/56e735bd-7e57-4dfc-b771-6a6fd1be2397)](https://youtu.be/71UL8TrE5Ls)\n\n## Demo script\n\n```python\nfrom gpt4_openai import GPT4OpenAI\n\n# Token is the __Secure-next-auth.session-token from chat.openai.com\nllm = GPT4OpenAI(token=my_session_token, headless=False, model='gpt-4')\n# GPT3.5 will answer 8, while GPT4 should be smart enough to answer 10\nresponse = llm('If there are 10 books in a room and I read 2, how many books are still in the room?')\nprint(response)\n```\n\n## DALL-E 3 support\n\nThis code was used for the demo gif above.\n\n```python\nfrom gpt4_openai import GPT4OpenAI\n\nllm = GPT4OpenAI(token=my_session_token, headless=False,\n                model='gpt-4' # DALL-E 3 only works with gpt-4\n                )\n\nimg_bytes = llm.generate_image('Generate an isometric image of a cute doggo inside a house.', image_path = './img_save_path.png')\n```\n\n## Browsing support\n\n```python\nfrom gpt4_openai import GPT4OpenAI\n\n# Token is the __Secure-next-auth.session-token from chat.openai.com\nllm = GPT4OpenAI(token=my_session_token, headless=False, model='gpt-4-browsing')\n# ChatGPT will first browse the web for the name/age of her boyfriend, then return the answer\nresponse = llm('What is the age difference between Dua Lipa and her boyfriend?')\nprint(response)\n```\n\n## Langchain support\n\n`GPT4OpenAI` actually extends `LLM` class from `langchain.llms.base`. So you can easily use this library inside langchain ecosystem. Example:\n\n```python\nfrom gpt4_openai import GPT4OpenAI\nfrom langchain import LLMChain\nfrom langchain.prompts.chat import (ChatPromptTemplate, SystemMessagePromptTemplate, AIMessagePromptTemplate, HumanMessagePromptTemplate)\n\ntemplate=\"You are a helpful assistant that translates english to pirate.\"\nsystem_message_prompt = SystemMessagePromptTemplate.from_template(template)\nexample_human = HumanMessagePromptTemplate.from_template(\"Hi\")\nexample_ai = AIMessagePromptTemplate.from_template(\"Argh me mateys\")\nhuman_message_prompt = HumanMessagePromptTemplate.from_template(\"{text}\")\n\nchat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, example_human, example_ai, human_message_prompt])\n\n# Token is the __Secure-next-auth.session-token from chat.openai.com\nllm = GPT4OpenAI(token=my_session_token)\n\nchain = LLMChain(llm=llm, prompt=chat_prompt)\nprint(chain.run(\"My name is John and I like to eat pizza.\"))\n```\n\nOutput will be:\n```\nAI: Ahoy, me name be John an' I be likin' ta feast on some pizza, arr!\n```\n\n## How to get the session token\n\n1. Go to https://chat.openai.com and open the developer tools by `F12`.\n2. Find the `__Secure-next-auth.session-token` cookie in `Application` \u003e `Storage` \u003e `Cookies` \u003e `https://chat.openai.com`.\n3. Copy the value in the `Cookie Value` field.\n\n![image](https://user-images.githubusercontent.com/19218518/206170122-61fbe94f-4b0c-4782-a344-e26ac0d4e2a7.png)\n\n## OpenAI's GPT4 vs other providers\n\nInitially, I tried [poe.com ](https://poe.com/) (private API implemented at [gpt4free](https://github.com/gptforfree/gpt4free/tree/main/quora)), but noticed that input context window is smaller than one of OpenAI ChatGPT. And the same goes for Bing's GPT4.\n\n## Installation\n\nTo install this Python package, run the following command:\n\n```bash\npip install gpt4-openai-api\n```\n\n## Dependencies\n\nThese dependencies get downloaded directly:\n\n- `undetected-chromedriver` (selenium browser)\n- `markdownify`\n- `langchain`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FErol444%2Fgpt4-openai-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FErol444%2Fgpt4-openai-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FErol444%2Fgpt4-openai-api/lists"}