diff --git a/.speakeasy/in.openapi.yaml b/.speakeasy/in.openapi.yaml index 4047ff2..c4a6011 100644 --- a/.speakeasy/in.openapi.yaml +++ b/.speakeasy/in.openapi.yaml @@ -6189,7 +6189,9 @@ components: type: string object: type: string - const: text_completion + enum: + - text_completion + - chat.completion created: type: number model: diff --git a/tests/e2e/completions.test.ts b/tests/e2e/completions.test.ts new file mode 100644 index 0000000..48dc64a --- /dev/null +++ b/tests/e2e/completions.test.ts @@ -0,0 +1,35 @@ +import { beforeAll, describe, expect, it } from 'vitest'; +import { OpenRouter } from '../../src/sdk/sdk.js'; + +describe('Completions E2E Tests', () => { + let client: OpenRouter; + + beforeAll(() => { + const apiKey = process.env.OPENROUTER_API_KEY; + if (!apiKey) { + throw new Error('OPENROUTER_API_KEY environment variable is required for e2e tests'); + } + + client = new OpenRouter({ + apiKey, + }); + }); + + describe('completions.generate()', () => { + it('should successfully generate a text completion', async () => { + const response = await client.completions.generate({ + model: 'meta-llama/llama-3.2-1b-instruct', + prompt: '5 + 7 = ', + maxTokens: 10, + stream: false, + }); + + expect(response).toBeDefined(); + expect(response.id).toBeDefined(); + // API returns chat.completion, SDK should accept both + expect(['text_completion', 'chat.completion']).toContain(response.object); + expect(Array.isArray(response.choices)).toBe(true); + expect(response.choices.length).toBeGreaterThan(0); + }, 30000); + }); +});