Character limit for text output · ChatGPT/OpenAI

I am using the following code:

// # popclip GPT Grammar (t=1)
// name: GPT Grammar (t=1)
// icon: symbol:bubbles.and.sparkles.fill
// entitlements: [network]
// before: cut
// after: paste-result
// language: javascript
const axios = require("axios");
const openai = axios.default.create({
  baseURL: "",
  headers: {
    Authorization: `Bearer sk-xxxxxx`,
let prompt;
if (popclip.modifiers.option) {
  prompt = "promp1";
} else {
  prompt = "prompt2";
  const { data } = await"chat/completions", {
  model: "gpt-4o",
  temperature: 1.0,
  max_tokens: 1024,
  messages: [
    { role: "system", content: prompt },
    { role: "user", content: popclip.input.text },
const response = data.choices[0].message.content.trim();
return response;

I primarily use ChatGPT to improve texts. I have often noticed that when correcting longer texts, the rest of the message is often missing. After about 250 to 265 characters, it stops.

Do I need to adjust the code to receive the complete message? If so, how?

I think it is likely the max_tokens parameter to the API call. An openai token represents about 3/4 of a word and the limit is based on the sum of tokens in the input and output, so ~250 words output sounds about right for setting of 1024 assuming similar sized input.

Unless you actually want to limit the amount of tokens processed per request (and this you get billed for), you can just omit the max_tokens and it will default to the model’s upper limit (which is 128,000 for gpt-4o).

PopClip itself doesn’t impose any limit on extensions’ text output size, it will only be limited by available system memory and processing capability. (And FWIW PopClip has a maximum input size of 10485760 utf-16 code units, i.e. about 10 million characters)

Were you able to get it working satisfactorily?