Title: CLI ChatGPT Client in PHP
Author: Alex Kirk
Published: May 24, 2023
Last modified: October 26, 2023

---

# CLI ChatGPT Client in PHP

May 24, 2023

For my personal use, I created [a CLI ChatGPT client](https://github.com/akirk/cli-chatgpt)
a few months ago. It has been very useful for me to have it available in the CLI
quickly whenever I needed it (caveat, [you need an API key](https://platform.openai.com/account/api-keys)!).

Unfortunately, for larger responses it can feel very slow, whereas the [web version](https://chat.openai.com/)
feels quite fast. But this is perceived speed because it shows you each word as 
it arrives and not just the whole response when finished (after all it is a completion
AI that generates the response word by word).

So now, I have added streaming support to it. It now feels almost too fast :) The
CLI has a few nice things such as readline support (i.e. you can go back to old 
queries with the up key) and it keeps all of your conversation in a text file. All
of this [in only 100 lines of PHP](https://github.com/akirk/cli-chatgpt/blob/main/chat.php).

![](https://alex.kirk.at/wp-content/uploads/sites/2/2023/05/chatgpt-block-variation-
response-1.gif)

###### Fediverse reactions

[AI](https://alex.kirk.at/category/ai/), [Explorations](https://alex.kirk.at/category/explorations/),
[Web](https://alex.kirk.at/category/web/)

[ChatGPT](https://alex.kirk.at/tag/chatgpt/), [LLMs](https://alex.kirk.at/tag/llms/)

Read this next

[Previous Post](https://alex.kirk.at/2023/05/23/1769578/)

![Alex Kirk](https://alex.kirk.at/wp-content/uploads/sites/2/2025/06/cropped-2025.
Alex-512x512-1-120x120.jpg)

Alex Kirk

@alex@alex.kirk.at

 **272** posts

 **280** followers

## One response to “CLI ChatGPT Client in PHP”

 1. ![anonymous Avatar](https://secure.gravatar.com/avatar/?s=48&d=mm&r=g)
 2. [anonymous](https://alex.kirk.at/2023/09/25/resuming-chatgpt-chats-in-cli/)
 3. [September 25, 2023](https://alex.kirk.at/2023/05/24/cli-chatgpt-client-in-php/comment-page-1/#comment-84657)
 4. I have issued an update to my CLI ChatGPT Client (see when I first announced it)
    so that you can now resume conversations. Here is…
 5. [Reply](https://alex.kirk.at/2023/05/24/cli-chatgpt-client-in-php/comment-page-1/?replytocom=84657#respond)

### Leave a Reply 󠀁[Cancel reply](https://alex.kirk.at/2023/05/24/cli-chatgpt-client-in-php/comment-page-1/?output_format=md#respond)󠁿

Your email address will not be published. Required fields are marked *

Comment *

Name *

Email *

Website

Δ

This site uses Akismet to reduce spam. [Learn how your comment data is processed.](https://akismet.com/privacy/)