Getting Max Token message for requests of estimated 300 tokens

I am converting some messy inputs into natural language.

Here is a typical prompt:
Please rewrite the following text as a single paragraph in the style of simple business English and in the first person. State how you will help the team using this idea: ‘More sales in the department. Managing and allocating marketing budgets to maximize ROI.’. State that previous to your most recent activity, you were a ‘I was at university.’ for about ‘4 years’ which is different to the job on offer but they are similar because of ‘Both require creativity and innovation.’. .

API Response for whole prompt
"{ “error”: { “message”: “This model’s maximum context length is 4097 tokens. However, you requested 4104 tokens (104 in the messages, 4000 in the completion). Please reduce the length of the messages or completion.”, “type”: “invalid_request_error”, “param”: “messages”, “code”: “context_length_exceeded” } } "

Why does it consider that a 4000 completion is requested?

if I run that same original prompt as two separate prompts, I get this info:
Prompt part A
Please rewrite the following text as a single paragraph in the style of simple business English and in the first person. State how you will help the team using this idea: ‘More sales in the department. Managing and allocating marketing budgets to maximize ROI.’.

Token data for prompt A:
{“prompt_tokens”:57,“completion_tokens”:122,“total_tokens”:179},

Prompt part B
Please rewrite the following text as a single paragraph in the style of simple business English and in the first person. State that previous to your most recent activity, you were a ‘I was at university.’ for about ‘4 years’ which is different to the job on offer but they are similar because of ‘Both require creativity and innovation.’. .

Token data for prompt B:
{“prompt_tokens”:77,“completion_tokens”:39,“total_tokens”:116}

Any help appreciated!

I resolved the problem by removing the following line from the php api documentation’s model I was working off:

“‘max_tokens’ => 4000,”

All great now!

Any request that exceeds model context length gets dropped as invalid.

Make sure that prompt_tokens + completion_tokens is less than the context length of the model.