New /v1/completions endpoint fails with specific HTTP Content-Type

So I spent many hours on this…I ended up using Fiddler and comparing the input and output of requests to the “old” and the “new” endpoints. In short, a header of:

Content-Type: application/json; charset=utf-8

Fails on:
https://api.openai.com/v1/completions

But works on:
https://api.openai.com/v1/engines/curie/completions

Huge props to @m-a.schenk for helping me on another thread, we tried a million things but I eventually had to dive deep and understand what was happening.

Here’s the repro steps:

THIS FAILS:

POST https://api.openai.com/v1/completions HTTP/1.1
Host: api.openai.com
Authorization: Bearer sk-VALID KEY
Content-Type: application/json; charset=utf-8
Content-Length: 137

{“model”:“curie:ft-user-mmuxbljf5hokaxayweacscpj-2021-07-30-06-40-45”,“prompt”:"Text: hello this is a nice bit of text. \n\n Keywords: "}

RESPONSE:
HTTP/1.1 400 Bad Request
Date: Sun, 01 Aug 2021 18:47:51 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 190
Connection: keep-alive
Vary: Origin
X-Request-Id: 89ff642d1b9229e7a8bf23feec8df7b7
Strict-Transport-Security: max-age=15724800; includeSubDomains

{
“error”: {
“message”: “unsupported Content-Type: application/json; charset=utf-8”,
“type”: “invalid_request_error”,
“param”: null,
“code”: null
}
}

THIS WORKS:

Request:
POST https://api.openai.com/v1/engines/curie/completions HTTP/1.1
Host: api.openai.com
Authorization: Bearer sk-VALID KEY
User-Agent: okgodoit/dotnet_openai_api
Content-Type: application/json; charset=utf-8
Content-Length: 97

{“prompt”:“Text: hello this is a nice bit of text. \n\n Keywords: “,“stream”:false,“stop”:”\n\n”}

RESPONSE:
HTTP/1.1 200 OK
Date: Sun, 01 Aug 2021 19:01:42 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Cache-Control: no-cache, must-revalidate
Openai-Model: curie:2020-05-03
Openai-Organization: user-mmuxbljf5hokaxayweacscpj
Openai-Processing-Ms: 177
Openai-Version: 2020-10-01
Strict-Transport-Security: max-age=15724800; includeSubDomains
Vary: Accept-Encoding
X-Request-Id: 7a0055ae4ab19fa6214d9c10f678980f

100
{“id”: “cmpl-3SB0QsDoayrb8NpPoR8ApnvfZ46Mf”, “object”: “text_completion”, “created”: 1627844502, “model”: “curie:2020-05-03”, “choices”: [{“text”: …", “index”: 0, “logprobs”: null, “finish_reason”: “length”}]}
0

I hope this helps someone else.
-Kevin

3 Likes

Thanks for flagging, that looks like a bug. Just rolled out a fix.

2 Likes

That’s great, what did the bug bounty end up being :wink:

1 Like

index.html:24 POST https://api.openai.com/v1/engines/curie/completions 400
sendTopicAndWordCount @ index.html:24
onclick @ index.html:13 when i use your URL and I get this and when I use v1/completion one --POST https://api.openai.com/v1/completions 429