| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import { describe, expect } from "bun:test"
- import { Effect } from "effect"
- import { LLM } from "../../src"
- import { LLMClient } from "../../src/route"
- import * as OpenRouter from "../../src/providers/openrouter"
- import { it } from "../lib/effect"
- describe("OpenRouter", () => {
- it.effect("prepares OpenRouter models through the OpenAI-compatible Chat route", () =>
- Effect.gen(function* () {
- const model = OpenRouter.model("openai/gpt-4o-mini", { apiKey: "test-key" })
- expect(model).toMatchObject({
- id: "openai/gpt-4o-mini",
- provider: "openrouter",
- route: "openrouter",
- baseURL: "https://openrouter.ai/api/v1",
- apiKey: "test-key",
- })
- const prepared = yield* LLMClient.prepare(LLM.request({ model, prompt: "Say hello." }))
- expect(prepared.route).toBe("openrouter")
- expect(prepared.body).toMatchObject({
- model: "openai/gpt-4o-mini",
- messages: [{ role: "user", content: "Say hello." }],
- stream: true,
- })
- }),
- )
- it.effect("applies OpenRouter payload options from the model helper", () =>
- Effect.gen(function* () {
- const prepared = yield* LLMClient.prepare(
- LLM.request({
- model: OpenRouter.model("anthropic/claude-3.7-sonnet:thinking", {
- providerOptions: {
- openrouter: {
- usage: true,
- reasoning: { effort: "high" },
- promptCacheKey: "session_123",
- },
- },
- }),
- prompt: "Think briefly.",
- }),
- )
- expect(prepared.body).toMatchObject({
- usage: { include: true },
- reasoning: { effort: "high" },
- prompt_cache_key: "session_123",
- })
- }),
- )
- })
|