Skip to content

Commit 1182d6d

Browse files
test: add regression test for issue #199 (PDF processing with OpenAI models) (#374)
* test: add regression test for issue #199 (PDF processing with OpenAI models) Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai> * fix: use exact model (gpt-4.1) from issue report in regression test Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai> * test: add gpt-5 test case to match issue report exactly Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai> * docs: remove root cause speculation, keep only known facts from issue Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai> * chore: use empty changeset for test-only change Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 7df7404 commit 1182d6d

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

.changeset/mighty-cloths-travel.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* Regression test for GitHub issue #199
3+
* https://github.com/OpenRouterTeam/ai-sdk-provider/issues/199
4+
*
5+
* Issue: "PDF Processing Fails on GPT-4.1 and GPT-5 Models via OpenRouter"
6+
*
7+
* Reported error:
8+
* AI_RetryError: Failed after 3 attempts. Last error: Provider returned error
9+
*
10+
* Error details from comments:
11+
* {"error":{"message":"Provider returned error","code":502,"metadata":{
12+
* "raw":"...server_error...","provider_name":"OpenAI"}}}
13+
*
14+
* This test verifies that PDF processing works with the exact models mentioned
15+
* in the issue (gpt-4.1 and gpt-5) using base64-encoded PDFs.
16+
*/
17+
import type { ModelMessage } from 'ai';
18+
19+
import { generateText } from 'ai';
20+
import { describe, expect, it, vi } from 'vitest';
21+
import { createOpenRouter } from '@/src';
22+
23+
vi.setConfig({
24+
testTimeout: 120_000,
25+
});
26+
27+
describe('Issue #199: PDF Processing Fails on GPT-4.1 and GPT-5 Models via OpenRouter', () => {
28+
const openrouter = createOpenRouter({
29+
apiKey: process.env.OPENROUTER_API_KEY,
30+
baseUrl: `${process.env.OPENROUTER_API_BASE}/api/v1`,
31+
});
32+
33+
// Helper to fetch and encode PDF
34+
async function fetchPdfAsBase64(): Promise<string> {
35+
const pdfBlob = await fetch('https://bitcoin.org/bitcoin.pdf').then((res) =>
36+
res.arrayBuffer(),
37+
);
38+
return Buffer.from(pdfBlob).toString('base64');
39+
}
40+
41+
it('should process PDF with openai/gpt-4.1', async () => {
42+
const model = openrouter('openai/gpt-4.1');
43+
const pdfBase64 = await fetchPdfAsBase64();
44+
45+
const messageHistory: ModelMessage[] = [
46+
{
47+
role: 'user',
48+
content: [
49+
{
50+
type: 'text',
51+
text: 'What is the title of this document? Reply with just the title.',
52+
},
53+
{
54+
type: 'file',
55+
data: `data:application/pdf;base64,${pdfBase64}`,
56+
mediaType: 'application/pdf',
57+
},
58+
],
59+
},
60+
];
61+
62+
const response = await generateText({
63+
model,
64+
messages: messageHistory,
65+
});
66+
67+
expect(response.text).toBeDefined();
68+
expect(response.text.length).toBeGreaterThan(0);
69+
expect(response.text.toLowerCase()).toContain('bitcoin');
70+
});
71+
72+
it('should process PDF with openai/gpt-5', async () => {
73+
const model = openrouter('openai/gpt-5');
74+
const pdfBase64 = await fetchPdfAsBase64();
75+
76+
const messageHistory: ModelMessage[] = [
77+
{
78+
role: 'user',
79+
content: [
80+
{
81+
type: 'text',
82+
text: 'What is the title of this document? Reply with just the title.',
83+
},
84+
{
85+
type: 'file',
86+
data: `data:application/pdf;base64,${pdfBase64}`,
87+
mediaType: 'application/pdf',
88+
},
89+
],
90+
},
91+
];
92+
93+
const response = await generateText({
94+
model,
95+
messages: messageHistory,
96+
});
97+
98+
expect(response.text).toBeDefined();
99+
expect(response.text.length).toBeGreaterThan(0);
100+
expect(response.text.toLowerCase()).toContain('bitcoin');
101+
});
102+
});

0 commit comments

Comments
 (0)