openrouter.test.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { describe, expect } from "bun:test"
  2. import { Effect } from "effect"
  3. import { LLM } from "../../src"
  4. import { LLMClient } from "../../src/route"
  5. import * as OpenRouter from "../../src/providers/openrouter"
  6. import { it } from "../lib/effect"
  7. describe("OpenRouter", () => {
  8. it.effect("prepares OpenRouter models through the OpenAI-compatible Chat route", () =>
  9. Effect.gen(function* () {
  10. const model = OpenRouter.model("openai/gpt-4o-mini", { apiKey: "test-key" })
  11. expect(model).toMatchObject({
  12. id: "openai/gpt-4o-mini",
  13. provider: "openrouter",
  14. route: "openrouter",
  15. baseURL: "https://openrouter.ai/api/v1",
  16. apiKey: "test-key",
  17. })
  18. const prepared = yield* LLMClient.prepare(LLM.request({ model, prompt: "Say hello." }))
  19. expect(prepared.route).toBe("openrouter")
  20. expect(prepared.body).toMatchObject({
  21. model: "openai/gpt-4o-mini",
  22. messages: [{ role: "user", content: "Say hello." }],
  23. stream: true,
  24. })
  25. }),
  26. )
  27. it.effect("applies OpenRouter payload options from the model helper", () =>
  28. Effect.gen(function* () {
  29. const prepared = yield* LLMClient.prepare(
  30. LLM.request({
  31. model: OpenRouter.model("anthropic/claude-3.7-sonnet:thinking", {
  32. providerOptions: {
  33. openrouter: {
  34. usage: true,
  35. reasoning: { effort: "high" },
  36. promptCacheKey: "session_123",
  37. },
  38. },
  39. }),
  40. prompt: "Think briefly.",
  41. }),
  42. )
  43. expect(prepared.body).toMatchObject({
  44. usage: { include: true },
  45. reasoning: { effort: "high" },
  46. prompt_cache_key: "session_123",
  47. })
  48. }),
  49. )
  50. })