Skip to content

Instantly share code, notes, and snippets.

@PawanOsman
Created February 2, 2023 21:31
Show Gist options
  • Save PawanOsman/be803be44caed2449927860956b240ad to your computer and use it in GitHub Desktop.
Save PawanOsman/be803be44caed2449927860956b240ad to your computer and use it in GitHub Desktop.

I created a dedicated HTTP API for official ChatGPT API, its using POST so it can handle long prompts and it supports setting all OpenAI properties

Example in NodeJS: (Its same for other languages you need to create a post request like below)

Ask ChatGPT a question

axios({
    method: 'post',
    url: 'https://chatgpt.pawan.krd/ask',
    headers: {
        'Content-Type': 'application/json'
    },
    data: JSON.stringify({
        "key": "sk-BBCnjlwWeCNlvyFk5hxxxxxxxxxxxxxxxxxxxxxxx",
        "prompt": "who are you?",
        "id": "default"
    })
})

// response 
{
  "status": true,
  "response": "Hello, how can i help you?"
}

// or 

{
  "status": false,
  "error" "Something went wrong"
}

Reset conversation by id

axios({
    method: 'post',
    url: 'https://chatgpt.pawan.krd/reset',
    headers: {
        'Content-Type': 'application/json'
    },
    data: JSON.stringify({
        "key": "sk-BBCnjlwWeCNlvyFk5hxxxxxxxxxxxxxxxxxxxxxxx",
        "id": "default"
    })
})

Init the API with all Options (Optional you can directly request ask if you don't want to modify the options)

await axios({
    method: 'post',
    url: 'https://chatgpt.pawan.krd/init',
    headers: {
        'Content-Type': 'application/json'
    },
    data: JSON.stringify({
        "key": "sk-BBCnjlwWeCNlvyFk5hxxxxxxxxxxxxxxxxxxxxxxx",
        "options": {
            "instructions": "You are ChatGPT, your name Is ChatGPT!"
        }
    })
});

// response
{
  "status": true
}

Options

options =  {
    temperature?: number;
    max_tokens?: number;
    top_p?: number;
    frequency_penalty?: number;
    presence_penalty?: number;
    instructions?: string;
    stop?: string;
}
@optionsx
Copy link

optionsx commented Feb 4, 2023

I created a dedicated HTTP API for official ChatGPT API

And how do we know this service won't just log/steal our API tokens?

you should know better atleast...
it's an apiKey which has a scope of openai models only, meaning it can't access any private data, use an empty openai key since it's free of charge
bruh.

@imbytecat
Copy link

What's the difference bewteen this and PawanOsman/ChatGPT? Why does this require an API Key and will I spend the credits?

@PawanOsman
Copy link
Author

PawanOsman commented Feb 6, 2023

What's the difference bewteen this and PawanOsman/ChatGPT? Why does this require an API Key and will I spend the credits?

PawanOsman/ChatGPT doesn't support options and runs on a single API Key which maybe gets rate limited sometimes because many peoples use it, no it doesn't charge you, even you can use a new account with 0 credit it will work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment