ModelsChatRankingDocs
DocsAPI ReferenceSDK Reference
DocsAPI ReferenceSDK Reference
  • Overview
    • Quickstart
    • Principles
    • Models
    • FAQ
    • Enterprise
  • Models & Routing
    • Auto Model Selection
    • Model Fallbacks
    • Provider Selection
  • Features
    • Presets
    • Tool Calling
    • Structured Outputs
    • Message Transforms
    • Model Routing
    • Zero Completion Insurance
    • ZDR
    • App Attribution
LogoLogo
ModelsChatRankingDocs
On this page
  • title: Effect AI SDK subtitle: Integrate OpenRouter using the Effect AI SDK headline: ‘Effect AI SDK Integration | OpenRouter SDK Support’ canonical-url: https://openrouter.ai/docs/guides/community/effect-ai-sdk og:site_name: OpenRouter Documentation og:title: ‘Effect AI SDK Integration - OpenRouter SDK Support’ og:description: ‘Integrate OpenRouter using the Effect AI SDK. Complete guide for integrating the Effect AI SDK with OpenRouter.’ og:image: https://openrouter.ai/dynamic-og?title=Effect%20AI%20SDK&description=Effect%20AI%20SDK%20Integration og:image:width: 1200 og:image:height: 630 twitter:card: summary_large_image twitter:site: ‘@OpenRouterAI’ noindex: false nofollow: false
  • Effect AI SDK
Community


title: Effect AI SDK subtitle: Integrate OpenRouter using the Effect AI SDK headline: ‘Effect AI SDK Integration | OpenRouter SDK Support’ canonical-url: https://openrouter.ai/docs/guides/community/effect-ai-sdk og:site_name: OpenRouter Documentation og:title: ‘Effect AI SDK Integration - OpenRouter SDK Support’ og:description: ‘Integrate OpenRouter using the Effect AI SDK. Complete guide for integrating the Effect AI SDK with OpenRouter.’ og:image: https://openrouter.ai/dynamic-og?title=Effect%20AI%20SDK&description=Effect%20AI%20SDK%20Integration og:image:width: 1200 og:image:height: 630 twitter:card: summary_large_image twitter:site: ‘@OpenRouterAI’ noindex: false nofollow: false

Effect AI SDK

You can use the Effect AI SDK to integrate OpenRouter with your Effect applications. To get started, install the following packages:

  • effect: the Effect core (if not already installed)
  • @effect/ai: the core Effect AI SDK abstractions
  • @effect/ai-openrouter: the Effect AI provider integration for OpenRouter
  • @effect/platform: platform-agnostic abstractions for Effect
$npm install effect @effect/ai @effect/ai-openrouter @effect/platform

Once that’s done you can use the LanguageModel module to define interactions with a large language model via OpenRouter.

TypeScript
1import { LanguageModel } from "@effect/ai"
2import { OpenRouterClient, OpenRouterLanguageModel } from "@effect/ai-openrouter"
3import { FetchHttpClient } from "@effect/platform"
4import { Config, Effect, Layer, Stream } from "effect"
5
6const Gpt4o = OpenRouterLanguageModel.model("openai/gpt-4o")
7
8const program = LanguageModel.streamText({
9 prompt: [
10 { role: "system", content: "You are a comedian with a penchant for groan-inducing puns" },
11 { role: "user", content: [{ type: "text", text: "Tell me a dad joke" }] }
12 ]
13}).pipe(
14 Stream.filter((part) => part.type === "text-delta"),
15 Stream.runForEach((part) => Effect.sync(() => process.stdout.write(part.delta))),
16 Effect.provide(Gpt4o)
17)
18
19const OpenRouter = OpenRouterClient.layerConfig({
20 apiKey: Config.redacted("OPENROUTER_API_KEY")
21}).pipe(Layer.provide(FetchHttpClient.layer))
22
23program.pipe(
24 Effect.provide(OpenRouter),
25 Effect.runPromise
26)
Was this page helpful?
Previous

Arize

Next
Built with
Effect AI SDK