chore: apply openai-go bugfix to fix openrouter response parsing (#27092)

Applies https://github.com/coder/openai-go/pull/3
Closes https://github.com/coder/coder/issues/26469

`kylecarbs/openai-go` was renamed to `coder/openai-go`

I've created a
[branch](https://github.com/coder/openai-go/tree/coder/pinned) to track
the changes we've made.
We're far behind `main` now, so we should make an effort to update this
as some point.

I've manually tested using OpenRouter + GLM 5.2 as the bug report states
and it works fine.

<img width="824" height="321" alt="image"
src="https://github.com/user-attachments/assets/804c527a-3a59-43bd-91c8-3b9bfb48df81"
/>
<img width="927" height="149" alt="image"
src="https://github.com/user-attachments/assets/35829bc2-5597-430c-8ede-bb2ebabc73a5"
/>

<details>

```
: OPENROUTER PROCESSING

: OPENROUTER PROCESSING

: OPENROUTER PROCESSING

: OPENROUTER PROCESSING

: OPENROUTER PROCESSING

: OPENROUTER PROCESSING

: OPENROUTER PROCESSING

: OPENROUTER PROCESSING

: OPENROUTER PROCESSING

: OPENROUTER PROCESSING

: OPENROUTER PROCESSING

: OPENROUTER PROCESSING

: OPENROUTER PROCESSING

: OPENROUTER PROCESSING

: OPENROUTER PROCESSING

: OPENROUTER PROCESSING

data: {"id":"gen-1783515596-pm90JeoPBXFHqVq3dDlL","object":"chat.completion.chunk","created":1783515596,"model":"z-ai/glm-5.2-20260616","provider":"Novita","choices":[{"index":0,"delta":{"content":"Yep","role":"assistant"},"finish_reason":null,"native_finish_reason":null}]}

data: {"id":"gen-1783515596-pm90JeoPBXFHqVq3dDlL","object":"chat.completion.chunk","created":1783515596,"model":"z-ai/glm-5.2-20260616","provider":"Novita","choices":[{"index":0,"delta":{"content":", I","role":"assistant"},"finish_reason":null,"native_finish_reason":null}]}

data: {"id":"gen-1783515596-pm90JeoPBXFHqVq3dDlL","object":"chat.completion.chunk","created":1783515596,"model":"z-ai/glm-5.2-20260616","provider":"Novita","choices":[{"index":0,"delta":{"content":"'m here","role":"assistant"},"finish_reason":null,"native_finish_reason":null}]}

data: {"id":"gen-1783515596-pm90JeoPBXFHqVq3dDlL","object":"chat.completion.chunk","created":1783515596,"model":"z-ai/glm-5.2-20260616","provider":"Novita","choices":[{"index":0,"delta":{"content":". What","role":"assistant"},"finish_reason":null,"native_finish_reason":null}]}

data: {"id":"gen-1783515596-pm90JeoPBXFHqVq3dDlL","object":"chat.completion.chunk","created":1783515596,"model":"z-ai/glm-5.2-20260616","provider":"Novita","choices":[{"index":0,"delta":{"content":" do you","role":"assistant"},"finish_reason":null,"native_finish_reason":null}]}

: OPENROUTER PROCESSING

data: {"id":"gen-1783515596-pm90JeoPBXFHqVq3dDlL","object":"chat.completion.chunk","created":1783515596,"model":"z-ai/glm-5.2-20260616","provider":"Novita","choices":[{"index":0,"delta":{"content":" need?","role":"assistant"},"finish_reason":null,"native_finish_reason":null}]}

data: {"id":"gen-1783515596-pm90JeoPBXFHqVq3dDlL","object":"chat.completion.chunk","created":1783515596,"model":"z-ai/glm-5.2-20260616","provider":"Novita","choices":[{"index":0,"delta":{"content":"","role":"assistant"},"finish_reason":"stop","native_finish_reason":"stop"}]}

data: {"id":"gen-1783515596-pm90JeoPBXFHqVq3dDlL","object":"chat.completion.chunk","created":1783515596,"model":"z-ai/glm-5.2-20260616","provider":"Novita","service_tier":null,"choices":[{"index":0,"delta":{"content":"","role":"assistant"},"finish_reason":"stop","native_finish_reason":"stop"}],"usage":{"prompt_tokens":4855,"completion_tokens":13,"total_tokens":4868,"cost":0.00479794,"is_byok":false,"prompt_tokens_details":{"cached_tokens":0,"cache_write_tokens":0,"audio_tokens":0,"video_tokens":0},"cost_details":{"upstream_inference_cost":0.00479794,"upstream_inference_prompt_cost":0.0047579,"upstream_inference_completions_cost":0.00004004},"completion_tokens_details":{"reasoning_tokens":0,"image_tokens":0,"audio_tokens":0}}}

data: [DONE]


```
</details>

Signed-off-by: Danny Kopping <danny@coder.com>
This commit is contained in:
Danny Kopping
2026-07-08 13:36:42 +00:00
committed by GitHub
parent affb359d13
commit f2e8d72100
4 changed files with 25 additions and 8 deletions
@@ -376,6 +376,15 @@ func TestResponsesOutputMatchesUpstream(t *testing.T) {
expectModel: "gpt-6.7",
expectPromptRecorded: "hello_wrong_format",
expectedClient: aibridge.ClientUnknown,
expectTokenUsage: &recorder.TokenUsageRecord{
MsgID: "resp_123",
Input: 11,
Output: 18,
ExtraTokenTypes: map[string]int64{
"output_reasoning": 0,
"total_tokens": 29,
},
},
},
}
@@ -632,18 +632,22 @@ func TestTraceOpenAIErr(t *testing.T) {
},
},
{
name: "trace_openai_responses_streaming_error",
name: "trace_openai_responses_streaming_wrong_format",
streaming: true,
fixture: fixtures.OaiResponsesStreamingWrongResponseFormat,
path: pathOpenAIResponses,
expectCode: http.StatusOK,
// The malformed event lacks a valid data field, so the SSE parser
// skips it and continues to the valid response.completed event.
// The stream is processed successfully and token usage is recorded.
expect: []expectTrace{
{"Intercept", 1, codes.Error},
{"Intercept", 1, codes.Unset},
{"Intercept.CreateInterceptor", 1, codes.Unset},
{"Intercept.RecordInterception", 1, codes.Unset},
{"Intercept.ProcessRequest", 1, codes.Error},
{"Intercept.ProcessRequest", 1, codes.Unset},
{"Intercept.RecordInterceptionEnded", 1, codes.Unset},
{"Intercept.RecordPromptUsage", 1, codes.Unset},
{"Intercept.RecordTokenUsage", 1, codes.Unset},
{"Intercept.ProcessRequest.Upstream", 1, codes.Unset},
},
},