Setting ChatGPT's Temperature: Introducing the ChatGPT API


Shane Delamore

Shane Brinkman-Davis Delamore is a master of the craft and passionate about UX design and programmer productivity.

Updated Jan 25, 2023

Go Beyond ChatGPT

At this point many people have tried the astonishing web experience of ChatGPT at As delightful and useful as that interface is, there is another option that is even more interesting to businesses and entrepreneurs. OpenAI is developing an API for ChatGPT. Though the ChatGPT API is currently in limited beta, there is an existing API for GPT-3, which is using the same (or very similar) models. The existing API provides nearly identical capabilities for "single-shot" prompts - just one. What's missing is multiple prompt sequence support, which will be coming with the ChatGPT API.

The GPT-3 API is already being adapted into many businesses. It can be a powerful tool to help customers generate names, summarize text, create variety in their call-flow software and many more.

The API also gives you raw access to the tool with additional parameters not available on the web interface. In this article we'll take a brief look at one of those parameters, temperature, and give a quick code example for how to play around with it.

Setting the Temperature

Temperature is a hyperparameter used in some natural language processing models, including ChatGPT, to control the level of randomness or "creativity" in the generated text. Higher temperatures result in more diverse and unpredictable output. Conversely, lower temperatures result in more conservative and predictable output.

When generating text with ChatGPT, the temperature can be set in conjunction with the prompt to control the level of similarity between the generated text and the prompt. For example, a high temperature value can be used to generate text that is more different from the prompt, while a low temperature value can be used to generate text that is more similar to the prompt. This can be useful in situations where the goal is to generate text that is similar to a given input, but with some level of variation or "creativity."

In addition to controlling the similarity between the generated text and the prompt, temperature can also be used to control the level of coherence and fluency in the generated text. Lower temperature values tend to result in more coherent and fluent text, while higher temperature values may result in more nonsensical or disjointed text. This makes temperature a powerful tool for fine-tuning the output of ChatGPT to suit the specific needs of a given application.

Let's give it a try...

Getting Started

echo "{}" > package.json
npm install openai dotenv @art-suite/cli  # NPMs we need...
echo "OPENAI_API_KEY=YOUR_API_KEY" > .env # insert your api key!
code cli.js                               # open cli.js in your favorite editor...

Paste this into your JS:

const cli = require("@art-suite/cli");
const { object, snakeCase } = require("art-standard-lib");
const { OpenAIApi, Configuration } = require("openai");

const openai = new OpenAIApi(
  new Configuration({
    apiKey: process.env.OPENAI_API_KEY,

  commands: {
    complete: props =>
          model: "text-davinci-003",
          max_tokens: 1000,
          temperature: 1,
          ...object(props, { withKey: (v, k) => snakeCase(k) }),
        .then(({ data }) => data.choices[0].text),

Try it out:

node cli.js complete --prompt "Write a limerick about OpenAI" --temperature 0
node cli.js complete --prompt "Write a limerick about OpenAI" --temperature 1
node cli.js complete --prompt "Write a limerick about OpenAI" --temperature 1.5

[Temperature 0]
There once was a company called OpenAI
That sought to make AI more humanely
They worked hard to make sure
That AI would endure
And that it would be a great ally

[Temperature 1]
There once was a team at OpenAI
Creating cutting edge AI
Their missions so noble
Yet sometimes a bit nimble
It seems like a great place to be.

[Temperature 1.5]
A hidden control force is OpenAI
using AI to give process and conclusions fa'Ty
Impress they Their neural nerdy cats
Loads as if brimful of subroutine bats
Connect what sustains whilst computers decree crocquaidl Heemrharn Seeingerraytediafx Wartohainaee!

Learn more about OpenAI's APIs here:

Use OpenAI's Playground to explore the API further.

Want to chat with us about opportunities for incorporating AI into your product?
Contact GenUI here

How can we help?

Can we help you apply these ideas on your project? Send us a message! You'll get to talk with our awesome delivery team on your very first call.