# Can I set max\_tokens for chatgpt turbo?

**URL:** <https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207>\
**Category:** API\
**Created:** [March 2, 2023, 8:31am UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207 "2023-03-02T08:31:50Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayfrdm](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/jayfrdm/32/35742_2.png) [@jayfrdm](https://community.openai.com/u/jayfrdm)\
**Post date:** [March 2, 2023, 8:31am UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/1 "2023-03-02T08:31:50Z")

</div>

Hi All,

So excited about this. But I’m getting massive reponses, and I cannot handle them. Is there a way to limit the response to a max tokens/words?

---

<div class="post-metadata">

**Author:** ![Zima](https://avatars.discourse-cdn.com/v4/letter/z/d78d45/32.png) [@Zima](https://community.openai.com/u/Zima)\
**Post date:** [March 2, 2023, 8:36am UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/2 "2023-03-02T08:36:19Z")

</div>

as per [OpenAI API](https://platform.openai.com/docs/api-reference/chat/create)  
max\_tokens

integer

Optional

Defaults to inf

The maximum number of tokens allowed for the generated answer. By default, the number of tokens the model can return will be (4096 - prompt tokens).

---

<div class="post-metadata">

**Author:** ![jayfrdm](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/jayfrdm/32/35742_2.png) [@jayfrdm](https://community.openai.com/u/jayfrdm)\
**Post date:** [March 2, 2023, 8:37am UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/3 "2023-03-02T08:37:37Z")

</div>

Thanks for the quick reply.  
This is my promp:

```auto
    generated_response = openai.ChatCompletion.create(
        model=model_engine,
        messages=prompt_messages,
        max_tokens=1024
    )

```

The interaction still costed me over 1300 tokens.

why?

---

<div class="post-metadata">

**Author:** ![Zima](https://avatars.discourse-cdn.com/v4/letter/z/d78d45/32.png) [@Zima](https://community.openai.com/u/Zima)\
**Post date:** [March 2, 2023, 8:39am UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/4 "2023-03-02T08:39:30Z")

</div>

How many input tokens did you use in prompt\_messages?

---

<div class="post-metadata">

**Author:** ![jayfrdm](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/jayfrdm/32/35742_2.png) [@jayfrdm](https://community.openai.com/u/jayfrdm)\
**Post date:** [March 2, 2023, 8:40am UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/5 "2023-03-02T08:40:48Z")

</div>

“completion\_tokens”: 589,  
“prompt\_tokens”: 1011,  
“total\_tokens”: 1600

---

<div class="post-metadata">

**Author:** ![Zima](https://avatars.discourse-cdn.com/v4/letter/z/d78d45/32.png) [@Zima](https://community.openai.com/u/Zima)\
**Post date:** [March 2, 2023, 8:42am UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/6 "2023-03-02T08:42:22Z")

</div>

There you have it… prompt\_tokens are also billed and max\_tokens is for generated answer only - completion\_tokens

---

<div class="post-metadata">

**Author:** ![jayfrdm](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/jayfrdm/32/35742_2.png) [@jayfrdm](https://community.openai.com/u/jayfrdm)\
**Post date:** [March 2, 2023, 8:51am UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/7 "2023-03-02T08:51:29Z")

</div>

But i don’t wasnt the reponse trucated. I just want openai to konw to work within those limits. Is that possible?

---

<div class="post-metadata">

**Author:** ![Zima](https://avatars.discourse-cdn.com/v4/letter/z/d78d45/32.png) [@Zima](https://community.openai.com/u/Zima)\
**Post date:** [March 2, 2023, 9:03am UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/8 "2023-03-02T09:03:42Z")

</div>

You want the total\_tokens to be under 1024?  
I guess you can count the prompt tokens and subtract from 1024 to get the available tokens for the completion.

---

<div class="post-metadata">

**Author:** ![jayfrdm](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/jayfrdm/32/35742_2.png) [@jayfrdm](https://community.openai.com/u/jayfrdm)\
**Post date:** [March 2, 2023, 3:09pm UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/9 "2023-03-02T15:09:13Z")

</div>

No, I want the total reponse to be under 1600 characters due to my bot limitations. How do you suggest I work around this?

---

<div class="post-metadata">

**Author:** ![raymonddavey](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/raymonddavey/32/14125_2.png) [@raymonddavey](https://community.openai.com/u/raymonddavey)\
**Post date:** [March 2, 2023, 5:29pm UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/10 "2023-03-02T17:29:12Z")

</div>

set max\_tokens to 1600

But you will also be billed for the prompt as well. This is on top of the tokens used for the output.

---

<div class="post-metadata">

**Author:** ![jayfrdm](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/jayfrdm/32/35742_2.png) [@jayfrdm](https://community.openai.com/u/jayfrdm)\
**Post date:** [March 2, 2023, 8:04pm UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/11 "2023-03-02T20:04:31Z")

</div>

I don’t mind the billing, I just candle handle a response that has more than 1600 characters (letters/spaces). Is there a way to tell openai to consider that and not generate responses longer then that?

---

<div class="post-metadata">

**Author:** ![georgei](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/georgei/32/116712_2.png) [@georgei](https://community.openai.com/u/georgei)\
**Post date:** [March 2, 2023, 8:56pm UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/12 "2023-03-02T20:56:22Z")

</div>

I doubt that it can count characters and also give you a good response.  
If your response is in English, then you can limit somewhat.

Given that the average number of characters in an English word is 4, then you need to have max 400 words to fit in 1600 characters.  
OpenAI documentation says that the ratio is 3:4 tokens to words.  
It means that the response can be at most 300 tokens.  
For safety, I would target a response of 250 tokens, because you might encounter longer words.

Note that the max\_tokens parameter includes the prompt as well. So you have to find out how many tokens are in the prompt and add 250 tokens to determine the max\_tokens parameter.

You can find the GPT-2 library to count the tokens on GitHub.

PS: the average word length is not 4, but you can find it.

---

<div class="post-metadata">

**Author:** ![jayfrdm](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/jayfrdm/32/35742_2.png) [@jayfrdm](https://community.openai.com/u/jayfrdm)\
**Post date:** [March 2, 2023, 8:57pm UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/13 "2023-03-02T20:57:46Z")

</div>

So if I put in max tokens, openai will try to generate a response that will fit with those tokens?

---

<div class="post-metadata">

**Author:** ![georgei](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/georgei/32/116712_2.png) [@georgei](https://community.openai.com/u/georgei)\
**Post date:** [March 2, 2023, 8:59pm UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/14 "2023-03-02T20:59:20Z")

</div>

Yes, but is not a guarantee.  
Sometimes there aren’t many tokens left.

---

<div class="post-metadata">

**Author:** ![anon10827405](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@anon10827405](https://community.openai.com/u/anon10827405)\
**Post date:** [March 2, 2023, 9:10pm UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/15 "2023-03-02T21:10:24Z")

</div>

I may be incorrect but I believe that the language model itself does not take in consideration the max tokens allowance.

It will write to whatever it desires (along with any instructions). If it hits the length, it will just cut suddenly (which you can counter by catching the stop reason and sending the prompt again). If the length is set to max, it doesn’t try and fill it to the max.

Although, if it’s set to max, you run a higher chance of getting it filled with garbage/noise

---

<div class="post-metadata">

**Author:** ![jayfrdm](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/jayfrdm/32/35742_2.png) [@jayfrdm](https://community.openai.com/u/jayfrdm)\
**Post date:** [March 2, 2023, 9:22pm UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/16 "2023-03-02T21:22:25Z")

</div>

This is what I’ve found. It just truncates. I wish there was a way to accomplish this. I’m sure I’m not the only one with this requirement. Anyone using an sms service might hit that limit of 1600 characters.

Perhaps I should put it in the prompt in plain lang?

---

<div class="post-metadata">

**Author:** ![ruby\_coder](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/ruby_coder/32/19875_2.png) [@ruby\_coder](https://community.openai.com/u/ruby_coder)\
**Post date:** [March 2, 2023, 11:25pm UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/17 "2023-03-02T23:25:19Z")

</div>

> [@jayfrdm](#):
>
> This is what I’ve found. It just truncates.

That is my experience as well.

`max_tokens` causes a STOP based on reason “length”.

🙂

---

<div class="post-metadata">

**Author:** ![jayfrdm](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/jayfrdm/32/35742_2.png) [@jayfrdm](https://community.openai.com/u/jayfrdm)\
**Post date:** [March 3, 2023, 2:47pm UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/18 "2023-03-03T14:47:42Z")

</div>

Is there a way to request a feature in the openai community?

---

<div class="post-metadata">

**Author:** ![mcheich](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/mcheich/32/39341_2.png) [@mcheich](https://community.openai.com/u/mcheich)\
**Post date:** [March 13, 2023, 3:22pm UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/19 "2023-03-13T15:22:57Z")

</div>

Running into the same issue.

I am developing for a very small display (size of wrist watch), and I want the responses to be terse. I thought max\_tokens would inform the model to formulate a response given so many tokens, but like people have said here - it just truncates the response.

I am exploring some prompt engineering, like, “Please respond briefly”, but I’d much rather have a way to limit the response…

Maybe what I’ll do is if the response exceeds the limit I want, I send back the response with the prompt, “say that more tersely”… and try that a couple times before delivering a truncated response, which is a an undesired user experience.

---

<div class="post-metadata">

**Author:** ![Levatron](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/levatron/32/20989_2.png) [@Levatron](https://community.openai.com/u/Levatron)\
**Post date:** [March 14, 2023, 11:08am UTC](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207/20 "2023-03-14T11:08:47Z")

</div>

Perhaps you could limit the answer by injecting a system message, asking gpt to answer any question with no more than (your required character count).

[Next page](https://community.openai.com/t/can-i-set-max-tokens-for-chatgpt-turbo/81207.md?page=2)
