[Custom API] ChatGPT - chat with your friend Nightbot!

Asked Mar 2, 2023·90 replies·Last activity 8 months ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

Hiya!
Saw a post here about asking for a ChatGPT command and thought that was a fun and good idea!
I've put something quickly together, not very well tested, but aye, throw some questions at it and let me know if it breaks.

Everytime you call this api it's considered a new conversation. You will receive a hastag and a code and the end of every message. This is a reference to your personal conversation.
Use this hashtag and code as first part of a new message to continue the conversation.

See example below:

Automatic installation:
Visit xgpt.gerhard.dev/dashboard and sign in with Nightbot to install this command with just a click.

When you sign in to our dashboard you will be able to customize settings for your personal AI chatbot. Give the bot more and detailed instructions for just your stream. Provide attional information about you or your stream, so the bot can answer more specific questions. Want the bot to speak in a certain language, a certain way, include emojis, be more funny? Endless opportunities and alot of fun!

You'll also be able to use your own OpenAI API key to avoid monthly limits, which we highly recommend!

Manual installation:

$(urlfetch https://xgpt.gerhard.dev/api/command?q=$(querystring))

Example command you can add:

!commands add !ai -cd=5 $(urlfetch https://xgpt.gerhard.dev/api/command?q=$(querystring))

Questions? Just let me know, enjoy!

The code for this command is available on Github, want to improve or suggest anything, feel free to submit it there: https://github.com/xgerhard/XGPT

90 replies

This service is free to use, however the OpenAI API does cost money based on the amount of requests made. While it's fun to see more people using this command, this does increase the monthly bill. If you like this command and want to support this project, consider helping with these monthly costs or buy me a beer with a one-time contribution: https://github.com/sponsors/xgerhard

xgpt08d77bd4da66ad2da63961146c96a909.png

I have it installed and working. Neat little code thanks for the effort. Now I can discover all the secrets of the Universe.

Thanks for trying it out! If you find something important, I hope you let me know ;)

Will do I haven't unleashed on my followers yet but they will give it a good run through

Out of interest what is the # at the end of an answer?

The hashtag and numbers lets you continue the conversation with the chatgpt bot. Otherwise each time you talk to it would be a unique interaction. But if you use the hashtag amd numbers it picks up the convesation where you left off.

Gehard posted example images of that use.

Gerhard said:
$(urlfetch https://xgpt.gerhard.dev/api/command?q=$(querystring))

great custom api! I've integrated this into my chat as well. Is there anyway to bake in a character limit? or at least force nightbot to not send multiple long messages in the chat? Maybe over a certain length it can go to a whisper? Just a suggestion. I think it's awesome though!

Hiya, thanks for trying it out! Replying to whisper is not an option. As explained in the first post, if you want shorter responses you can specify it in your message, for example: "explain pi in 100 characters".

Gerhard said:
Hiya!
Saw a post here about asking for a ChatGPT command and thought that was a fun and good idea!
I’ve put something quickly together, not very well tested, but aye, throw some questions at it and let me know if it breaks.

Everytime you call this api it’s considered a new conversation. You will receive a hastag and a code and the end of every message. This is a reference to your personal conversation.
Use this hashtag and code as first part of a new message to continue the conversation.

how can i add it on my twitch channel everyone seems to know how to do it but i don’t can you guys help me?

Hey everyone, and more specifically @Pearly Panda!

EDIT: the API has been updated, and the following message is no longer up-to-date, you don't need to add the extra string to "fix" the command, so feel free to disregard this message, leaving it up for posterity/context.

If you want to make ChatGPT (attempt to) shorten its answers without having to write it in every time, so it doesn't cut the message with ellipsis, you can edit the command as such:

!editcom !xgpt $(urlfetch https://xgpt.gerhard.dev/api/command?q=$(querystring)%20answer%20in%20150%20characters%20or%20less)

It adds the following string to your request for every command call: "answer in 150 characters or less."
I limited to 150 characters because I noticed that it seems to cuts the message at around 165 characters.
⚠️ It works fairly well, but there are still mishaps sometimes.

Hey @Grand Eagle!

xgerhard already gave an example on how to do it in their introduction post:

Gerhard said:
Example command you can add:

```
!commands add !xgpt -cd=5 $(urlfetch https://xgpt.gerhard.dev/api/command?q=$(querystring))
```

Simply copy/paste the !commands add ... in your chat (it'll only work if you already added Nightbot to your chat).

If you rather add the command through the dashboard, give the command a name, for example !xgpt, and copy/paste that bit in the Message field:

Gerhard said:
```
$(urlfetch https://xgpt.gerhard.dev/api/command?q=$(querystring))
```
Jaunty Unicorn said:
$(urlfetch https://xgpt.gerhard.dev/api/command?q=$(querystring)%20answer%20in%20150%20characters%20or%20less)

I have really been hammering on this and outside of a few cannot reach external server errors it has been a blast. I am wondering if it is possible to make a call to xgpt from another script. I was hoping to have it recognize an input from the sending action...

[This Code I Have]
$(user), You drew $(eval responses=[The Fool!,The Magician!,The High Priestess!,The Empress!,The Emperor!,The Hierophant!,The Lovers!,The Chariot!,Justice!,Strength!,The Hermit!,Wheel of Fortune!,The Hanged Man!,Death!,Temperance!,The Devil!,The Tower!,The Star!,The Moon!,The Sun!,Judgement!,The World!];responses[Math.floor(Math.random()*responses.length)])

User:!tarot
Nightbot $(user) you chose 'INSERT-CARD-NAME-HERE'
[Alias Call Here]
This is where I am confused how to pass of the results of command a to another command called from the !alias

[This is the code I am looking to Create]
Ex: !xgpt What is the meaning of INSERT-CARD-NAME-HERE in Tarot?
(Getting the input from !tarot results)

Nightbot: xgtp: INSERT-CARD-NAME-HERE in Tarot means Blah Blah Blah

What I am imagining is creating an in between command at the End of the Tarot command and then handing that off to xgtp? I am just lost at where to start.

Thanks for any help - JTS

Hey @Fleet Pufferfish!

An alias overrides the output of the first command, so what you're trying to do is not possible.
And using an AI to pull the meaning of the cards could be a bit excessive, what makes me say that is that you already made a similar topic that has a better/simpler/easier solution in my opinion.

Thank you for this Emily! Could I adjust that 150 value to 350, or whatever my own character limit is? And I’d do what you did and dial it back just before that limit as well.

Thanks

Yeah you can adjust to your preference. Character limit is 400, minus the username and conversation ID, so 350 should work.

EDIT: the API has been updated, and the following message is no longer up-to-date, you don't need to add the extra string to "fix" the command, so feel free to disregard this message, leaving it up for posterity/context.

From my experience, the output is cut short with ellipsis at 165 characters, regardless of the platform limit, I'm really not sure why.
But if you want to increase it to 350, I highlighted the number you'd need to edit:

Jaunty Unicorn said:
%20answer%20in%20150%20characters%20or%20less

Thanks for testing this! I now send an extra message with every request: "answer in X characters or less".
So this extra part should not be needed anymore, but everyone can choose their own character limits ofcourse.

I put an X, since I dont have the exact number yet, I'm playing around with this number and a max_tokens value I can send to the ChatGPT API, which is their sort of way of counting words/characters. Trying to find the sweet spot between not reaching timeout limits for Nightbot, and also not sending cut off responses.
So please try it out, and let me know your findings. If responses are cut off frequently or commands are timing out I can adjust these numbers.

First of all congratulations on the api and thank you very much.

Since a few hours nightbot always responds "ChatGPT took to long to respond. Please try again in a bit. ResidentSleeper"

Hiya, saw you posted this messages a couple hours ago, I updated the api (see message above) after that which should hopefully fix most of these timeout messages.

It's been working perfectly for a few hours. It does not show the error of "Error Connecting To Remote Server" or “ChatGPT took to long to respond. Please try again in a bit. ResidentSleeper”
Thank you!

Thanks a lot, appreciate it!
The new version seems to be working great!

Gonna try this out tonite. Blessings to you.

Is there a way for him to respond only in Portuguese?

Hiya, I've noticed when I asked a qeustion in a foreign language the bot usually responds in that same language. Or you can ask the bot to reply in a specific language by specifying that in your question.. " answer in portuguese".

Hi! I started using this about 2 days ago and it was working perfectly fine but as of yesterday, the only response I now get is "Nightbot: Error, unexpected response.."

@Snug Flamingo @Spry Giraffe thanks for the ping, that should be fixed!

Ah yes, good point! I will have a look at providing the correct platform name. The character limit will be the same for nightbot responses.

Is there a way to make it not so....pure? My chat can get pretty raunchy at times. We asked a few pg-13 questions and it seems to have a default G-rated only setting.

@Gerhard thanks for the amazing work with this! any plans to allow custom bots to utilize the fetch URL so we don't have to use nightbot or are there limitations with that?

Hiya, hmm I don't really have control in what kind of way the bot responds, the only instruction I give is to be a helpfull chat assistant. Funny enough the bot is smart enough to abide the Twitch ToS.

Hiya, for now I keep it Nightbot only, reason for that is so I have some control over the usage of the API. Otherwise other applications (not just chatbots) might start using the API which I don't want to yet, since the OpenAI API usage is not free.

Just brainstorming, might add a option for streamers or bots to add their own OpenAI API key so their costs are just for their own usage.

This should now be fixed, the bot is now instructed with the correct platform.

Fantastic work! Added to one of the channels I've modded for and chat absolutely loved it :heartpulse:

Hi xgerhard, is there anyway to change the language say for French speakers or will this do it on its own? I've never thought about how that works with chatgpt.

You can just ask the bot to answer in French directly in the command, e.g.:


!addcom !chatbot $(urlfetch https://xgpt.gerhard.dev/api/command?q=$(querystring)%20write%20in%20french)

Note the words between the space characters %20:

q=$(querystring)write%20in%20french)

It works pretty well except in really rare cases. And you can also try to add another preferences in the command.

Hey @Sable Zebra!

@Mild Zebra gave you a correct answer, however, if you talk to ChatGPT in French, it should answer you in French by default.

OpenAI enforces rules on ChatGPT's answers, and it'll always be G-rated.

I tried using it in Japanese. I cannot devise a way to make the returned text uninterrupted. What should I do?

Could you by chance allow other chatbots to perform requests? like streamelements?

Hiya, currently no plans to add other bots sorry!

Hiya, I'm not sure what you mean. Is the japanese text returned by the bot cut off mid-sentence? Curious if japanese characters are being processed wrong in my script. Do you have an example prompt I could use to test it.

It is used as follows
"$(urlfetch https://xgpt.gerhard.dev/api/command?q=$(querystring)%20write%20in%20Japanese)"

However, the returned Japanese content is cut off in the middle of a sentence.
Regardless of whether you say "answer within n characters", "within n characters in Japanese", or "answer within n characters using 2-byte characters as a single character", the sentence will come back broken.

Thanks for the info! Since i dont speak japanese have you an example input you ask the bot? So I can test it here :)

Whenever you ask a question about a game, for example, that seems to have a lot of letters to be returned, there is always a disconnect.

Below is an example of a question and answer written in Japanese.
("。" is the English word "." in English.)

"
Example:Project Zomboidについて。
Nightbot: てふに: Project Zomboidは、サバイバルホラーゲームであり、ゾンビの大群と戦いながら、物資の調達や建物の改築、共同生活の構築を行うことが目的です。高い自由度とリ" #y5h
"

Thanks for the info, I will look into it.

This used to work great but recently have been getting the error “Remote Server Returned Code 500” Any idea what this means? Thanks! Been happening the last couple of days.

Thanks for letting me know! If an error happens a couple days, you may always ping me earlier! 😃
Not sure how long this error was there, for now I put a band-aid on it.

Thank you! Will test it out now.

It is conversation id where the bot (chatgpt) will identify u are the same user since many other users are using at the same time in many conversation sessions. U can resume with the same conversation id if u want to continue the same topic that u have chatted before (as shown in the screenshot in the starter thread).

Hola, como puedo solucionar el error de: Error Connecting To Remote Server , me a pasado mucho y no se arregla:c

I'm getting that error occasionally with my own chatgpt bot that uses nightbot. I feel that it happens when nightbot gets rate limited. The logs on the server that I'm sending the fetchURL requests to show that the information from openAI is being received but it's not getting sent back to twitch properly resulting in the "Error Connecting to Remote Server" error.

I'm not sure what can be done to mitigate these errors. Maybe @Gerhard has some thoughts?

espero que el tenga alguna idea porque necesito una solución :c

@Hushed Badger please use english so I can help you better.
@Royal Rooster so yes that error means that my website took to long to respond, I turned down some settings with the OpenAI API, so it communicates faster. Hopefully that helps.

I mean that the gpt chat command does not work for me, it shows me the error Connecting to remote server. how can I solve it? :c

Hmm yes I do see a bunch of errors which I'm looking into now..

@Hushed Badger @Royal Rooster Please let me know if it's resolved now!

I was so confused why it wasn't working, the reason was bad code obviously.
Explanation for whoever is interested, the code tries to generate a # code for each conversation. In the background theres a cleanup running which deletes old conversations, which stopped for no reason. So eventually there were no more codes available, but the code keeps trying endlessly.. So yes, never make endless loops lol :upside_down_face:

thank you very much now it works much better

Is there a way to remove the need for a conversation recall code and have the "personality" remain static and constantly learning to the streams quirks rather than resetting with every question?

Hiya, working on something like this.. details later! Thanks for the suggestions.

How about streamlabs cloudbot in addition to nightbot?

Hiya, no plans currently to expand to other bots.

Hello! Im using the same OpenAI Nightbot integration (by guide from YouTube video called "How To Connect ChatGPT To Your Twitch Chat") and getting error "Error Connecting To Remote Server" quite often. I was never able to identify the pattern of its appearance. I assume that the problem may be that sometimes the bot formulates a message that is too long, and while it is being cut off, the bot timeout passes, which is why it throws an error. Perhaps you have some progress in learning and fixing this issue?

if am not wrong . you are referring to this video. that video have no connection to this thread. this thread gives a way easier way of doing it.

Hi, maybe what I'm asking for is crazy but I don't need it, I'm putting it more as an idea in case it's possible to implement.
I was wondering if it is possible to customize the api with some parameters so that it is more in line with the type of channel, for example adding the parameter, "fun" so that the answers returned by the bot are more fun or more serious, this was just an example but it would be great if there were more ways to implement a more personalized ai and not just a chat assistant.
Anyway, it is an incredible api, I already implemented it to the channel that I moderate

hey @Gerhard is it possible to add a parameter for our own API key instead of using the one provided within.

Hey @Early Sheep @Steady Koala thanks for the suggestions!
These both features is something I wanted to add and already built months ago, but somehow never finished it. I will revisit this project soon to implement these features, and will let you know here :)

Howdy y'all! Today is update day. Launched a dashboard for your XGPT settings, there can set your own OpenAI API key to avoid monthy limits, but also set channel settings to make the AI more fitting for your channel. Add info about yourself, or give specific instructions for example to respond in a certain language.

Have a look at: xgpt.gerhard.dev/dashboard

Questions/bugs? Most likely, aint nobody got time to test everything, just shoot me a message here! :upside_down_face:

@Steady Koala @Early Sheep @Velvet Dodo @Sable Zebra

Hi, first things first to appreciate your work and everything works fine. However, i think there is an issue to make it work on another channel. whenever i change the ai instructions and talk with the bot in my own channel works really fine. BUT, as a moderator on another channel, it ignores the instructions and talks formal language. How do i fix this?

Thanks for the feedback! Each channel owner has to setup their own instructions by singing in to the dashboard. Settings aren't shared with the token in the url, this is just a security check for when users use their own OpenAI api key.

God Tier. loved the interface. puts my stuff to shame.
will check the usage once i get some time

The error “Error Connecting To Remote Server” keeps occurring. I wonder if this is due to excessive usage at the end of the month.

@Urban Mammoth Sorry about that, it was a database error on my end. Should be fixed now :)

Oh, thank you!! It's working! I thought the quota was over so I tried to wait until February 1st.

why when i try to use this ai in the live chat, the nightbot response was "​​Error: Thanks for using this command! :) Unfortunately the OpenAI ChatGPT API is not free and it seems like we hit our monthly limit, this will reset first of the month. You can support this project a"

Hiya! Ah the message is cut off, I will change that.
But the meaning is that my command is using the OpenAI ChatGPT API, which isn't free. I pay a set amount each month, when we reach this number the command will stop working.

There is a way to fix this however, you can register your own ChatGPT API key and pay for your channel usage only (this will most likely be just a few cents a month).

1. Register your API key: https://platform.openai.com/docs/overview
2. Sign in at the XGPT dashboard, and enter your API key: https://xgpt.gerhard.dev/dashboard

If you have any questions, let me know :)

how to set in nighbot my chatgpt api is not work how to i buy

yes ye xgerhad not work in nightbot error

I’m getting that error occasionally with my own chatgpt bot that uses nightbot. I feel that it happens when nightbot gets rate limited. The logs on the server that I’m sending the fetchURL requests to show that the information from openAI is being received but it’s not getting sent back to twitch properly resulting in the “Error Connecting to Remote Server” error.

I’m not sure what can be done to mitigate these errors. Maybe @xgerhard (link expired) has some thoughts?

Does adding your own key use the latest model or does it stay with same knowledge cut off ?

Hiya, using your own key won't effect the model used. The app currently uses the GPT-4o mini model (cutoff October, 2023)

Looks like everything went down. Can't log into dashboard .

Thanks for the heads up. Not sure whats wrong. Not in the position at the moment to fix it, will have a lkook tomorrow, apologies.

Awesome . Sent you a couple $$ PayPal . In case you need coffee.

You didn’t need to do that, but thank you! :)

Everything should be working fine again, let me know if you encounter any issues.

Subject: Inquiry: Recurring "Monthly Usage Limit" Error & Indian Sponsorship Payment

Hello xgerhard,

I am a user of your xGPT service, which I run on my YouTube channel, 'Mango music live '.

I am facing a recurring critical issue where the bot displays the error: "Error: XGPT has reached it monthly usage limit."

I understand that the intended solution is to sponsor the project via the provided link to continue usage.

The Challenge: I am based in India and am currently unable to make international payments for sponsorship due to limitations on my local debit/Visa cards (lack of international payment enablement).

My Request: I am keen to support your project and resolve this usage limit issue. Could you please let me know if there are any alternative payment methods available for Indian users? Specifically, are you able to accept support via local Indian methods like UPI, Google Pay India, or any local bank transfer?

Any information on alternative sponsorship methods would be greatly appreciated so I can ensure the bot remains active on my channel.

Thank you for your time and assistance.

photo_2025-12-02_08-08-42.jpg

Apologies late reply, my creditcard expired thats why the shared pool of tokens was not reset this month. About the payment methods, not much I can do sorry, maybe OpenAI supports one of your local payment methods, so you can use your own API key for your channel. That way the tokens will never run out for your channel. Check platform.openai.com

Didn't find your answer? The community is on Discord.

Ask on Discord