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)

[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/)

## 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. [Log in to Reply](https://alex.kirk.at/wp-login.php?redirect_to=https%3A%2F%2Falex.kirk.at%2F2023%2F05%2F24%2Fcli-chatgpt-client-in-php%2F)

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

Only people in [my network](https://alex.kirk.at/friends/) can comment.

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