{"id":13464007,"url":"https://github.com/tnb-labs/ChatGPT-PHP","last_synced_at":"2025-03-25T09:31:26.648Z","repository":{"id":89148420,"uuid":"607129026","full_name":"tnb-labs/ChatGPT-PHP","owner":"tnb-labs","description":"Official and Reverse Engineered ChatGPT PHP SDK (Not GPT-3)","archived":true,"fork":false,"pushed_at":"2023-08-09T07:41:19.000Z","size":105,"stargazers_count":113,"open_issues_count":1,"forks_count":29,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-22T17:24:17.526Z","etag":null,"topics":["chatgpt","chatgpt-api","openai","openai-api","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/tnb-labs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-02-27T11:26:13.000Z","updated_at":"2024-11-20T05:23:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"28f85dc9-e7ae-4eb8-a014-fef8f8cd4b95","html_url":"https://github.com/tnb-labs/ChatGPT-PHP","commit_stats":null,"previous_names":["thetnb/chatgpt-php","haozi-team/chatgpt-php","tnb-labs/chatgpt-php"],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tnb-labs%2FChatGPT-PHP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tnb-labs%2FChatGPT-PHP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tnb-labs%2FChatGPT-PHP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tnb-labs%2FChatGPT-PHP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tnb-labs","download_url":"https://codeload.github.com/tnb-labs/ChatGPT-PHP/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245435165,"owners_count":20614849,"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":["chatgpt","chatgpt-api","openai","openai-api","php"],"created_at":"2024-07-31T14:00:31.999Z","updated_at":"2025-03-25T09:31:21.639Z","avatar_url":"https://github.com/tnb-labs.png","language":"PHP","funding_links":[],"categories":["Awesome PHP Open AI Projects"],"sub_categories":[],"readme":"# ChatGPT PHP SDK | [Package](https://packagist.org/packages/haozi-team/chatgpt-php)\n\n[![Total Downloads](https://poser.pugx.org/HaoZi-Team/ChatGPT-PHP/d/total.svg)](https://packagist.org/packages/haozi-team/chatgpt-php)\n[![Latest Stable Version](https://poser.pugx.org/HaoZi-Team/ChatGPT-PHP/v/stable.svg)](https://packagist.org/packages/haozi-team/chatgpt-php)\n[![License](https://poser.pugx.org/HaoZi-Team/ChatGPT-PHP/license.svg)](https://packagist.org/packages/haozi-team/chatgpt-php)\n\nOfficial and Reverse Engineered ChatGPT API for PHP.\n\nReconstruct from @acheong08's [ChatGPT](https://github.com/acheong08/ChatGPT)\n\n# Installation\n\n`composer require haozi-team/chatgpt-php`\n\n# V1 Web ChatGPT\n\n\u003e Uses `chat.openai.com`\n\u003e - Free\n\u003e - Rate limited\n\u003e - Needs Bypassing Cloudflare\n\n\u003e Default api endpoint is `https://ai.fakeopen.com/api/` by @pengzhile\n\u003e \n\u003e OpenAI rate limit: 50 requests per hour on free accounts. You can get around it with multi-account cycling\n\u003e \n\u003e Plus accounts has around 150 requests per hour rate limit\n\u003e \n\u003e Arkose Token: Recently, OpenAI began to require Arkose Token while bypassing Cloudflare request conversation API, usually the SDK can get it automatically through @pengzhile's API\n\n## Configuration\n\n1. Create account on [OpenAI's ChatGPT](https://chat.openai.com/)\n2. Save your email and password\n\n### Authentication\n\n#### - Access token\n\nLogin OpenAI account and go to [https://chat.openai.com/api/auth/session](https://chat.openai.com/api/auth/session)\nto get your access_token.\n\n```json\n{\n  \"access_token\": \"\u003caccess_token\u003e\"\n}\n```\n\nThe access_token is valid for 30 days.\n\n## Developer API\n\n### Basic example\n\n```php\n\u003c?php\nuse HaoZiTeam\\ChatGPT\\V1 as ChatGPTV1;\n\n$chatGPT = new ChatGPTV1();\n$chatGPT-\u003eaddAccount('\u003cyour_access_token\u003e');\n\n$answers = $chatGPT-\u003eask('Hello, how are you?');\nforeach ($answers as $item) {\n    print_r($item);\n}\n//Array(\n//    'answer' =\u003e 'I am fine, thank you.',\n//    'conversation_id' =\u003e '\u003cuuid\u003e',\n//    'parent_id' =\u003e '\u003cuuid\u003e',\n//    'model' =\u003e 'text-davinci-002-render-sha',\n//    'account' =\u003e '0',\n//)\n```\n\n### Advanced example\n\nYou can pass \"baseUrl\" to the first parameter to set a custom API endpoint.\n\n```php\n\u003c?php\nuse HaoZiTeam\\ChatGPT\\V1 as ChatGPTV1;\n\n$chatGPT = new ChatGPTV1('https://chat.openai.com/backend-api/');\n```\n\nMore refer to the [wiki](https://github.com/HaoZi-Team/ChatGPT-PHP/wiki/V1-Advanced-examples) for advanced developer\nusage.\n\n# V2 Official ChatGPT\n\n\u003e Recently released by OpenAI\n\u003e - Costs money\n\nGet API key from https://platform.openai.com/account/api-keys\n\n## Developer API\n\n### Basic example\n\n```php\n\u003c?php\nuse HaoZiTeam\\ChatGPT\\V2 as ChatGPTV2;\n\n$chatGPT = new ChatGPTV2('sk-\u003cyour_api_key\u003e');\n$chatGPT-\u003eaddMessage('You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.', 'system');\n\n$answers = $chatGPT-\u003eask('Hello, how are you?');\nforeach ($answers as $item) {\n    print_r($item);\n}\n```\n\n### Advanced example\n\nYou can pass \"baseUrl\" to the second parameter to set a custom API endpoint.\n\n```php\n\u003c?php\nuse HaoZiTeam\\ChatGPT\\V2 as ChatGPTV2;\n\n$chatGPT = new ChatGPTV2('sk-\u003cyour_api_key\u003e', 'https://api.openai.com/');\n```\n\nYou can use `addMessage` to add messages to the conversation.\n\n```php\n\u003c?php\nuse HaoZiTeam\\ChatGPT\\V2 as ChatGPTV2;\n\n$chatGPT = new ChatGPTV2('sk-\u003cyour_api_key\u003e');\n$chatGPT-\u003eaddMessage('You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.', 'system');\n$chatGPT-\u003eaddMessage('Hello, how are you?', 'user');\n$chatGPT-\u003eaddMessage('I am fine, thank you.', 'assistant');\n\n$answers = $chatGPT-\u003eask('What did I ask you before?');\nforeach ($answers as $item) {\n    print_r($item);\n}\n//Array(\n//    'answer' =\u003e 'Hello, how are you?',\n//    'id' =\u003e 'cmpl-xxxxx',\n//    'model' =\u003e 'gpt-3.5-turbo',\n//    'usage' =\u003e [\n//        \"prompt_tokens\": 9,\n//        \"completion_tokens\": 12,\n//        \"total_tokens\": 21,\n//    ],\n//)\n```\n\nYou can set the `stream` parameter to `true` to get a stream for output answers as they are generated.\n\n```php\n\u003c?php\nuse HaoZiTeam\\ChatGPT\\V2 as ChatGPTV2;\n\n$chatGPT = new ChatGPTV2('sk-\u003cyour_api_key\u003e');\n$chatGPT-\u003eaddMessage('You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.', 'system');\n\n$answers = $chatGPT-\u003eask('Hello, how are you?', null, true);// A Generator\nforeach ($answers as $item) {\n    print_r($item);\n}\n```\n\n# Disclaimers\n\nThis is not an official OpenAI product. This is a personal project and is not affiliated with OpenAI in any way. Don't\nsue me.\n\n# Credits\n\n- [acheong08](https://github.com/acheong08) - Python ChatGPT API\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftnb-labs%2FChatGPT-PHP","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftnb-labs%2FChatGPT-PHP","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftnb-labs%2FChatGPT-PHP/lists"}