mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 20:00:47 +00:00
feat(vercel-ai-gateway): support embeddings, images and credit usage
Extend Vercel AI Gateway beyond chat: add OpenAI-compatible embeddings and image generation endpoints, credit balance fetch on the usage dashboard, retry on 429, and models catalog fetcher. Thinking/reasoning mapping is omitted pending a project-wide refactor. Co-authored-by: Ngô Tấn Tài <tantai@newnol.io.vn> Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
committed by
decolua
co-authored by
Cursor
parent
d9b030011f
commit
b33cbb0280
@@ -263,6 +263,38 @@ describe("handleImageGenerationCore", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("handles Vercel AI Gateway image generation as OpenAI-compatible", async () => {
|
||||
global.fetch.mockResolvedValueOnce(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
created: 1234567890,
|
||||
data: [{ url: "https://example.com/vercel-image.png" }],
|
||||
}),
|
||||
{ status: 200, headers: { "Content-Type": "application/json" } }
|
||||
)
|
||||
);
|
||||
|
||||
const result = await handleImageGenerationCore({
|
||||
body: { prompt: "A watercolor castle", n: 1, size: "1024x1024" },
|
||||
modelInfo: { provider: "vercel-ai-gateway", model: "openai/gpt-image-1" },
|
||||
credentials: { apiKey: "vag-test-key" },
|
||||
log: null,
|
||||
});
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(global.fetch).toHaveBeenCalledWith(
|
||||
"https://ai-gateway.vercel.sh/v1/images/generations",
|
||||
expect.objectContaining({
|
||||
method: "POST",
|
||||
headers: expect.objectContaining({
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer vag-test-key",
|
||||
}),
|
||||
body: expect.stringContaining('"model":"openai/gpt-image-1"'),
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("handles HuggingFace binary response", async () => {
|
||||
const imageBuffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]); // PNG header
|
||||
global.fetch.mockResolvedValueOnce(
|
||||
|
||||
Reference in New Issue
Block a user