For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
ModelsChatRankingsDocs
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
  • Overview
    • Quickstart
    • Principles
    • Models
    • Stripe Projects
    • FAQ
    • Report Feedback
  • Models & Routing
    • Model Fallbacks
    • Provider Selection
    • Auto Exacto
    • Private Models
  • Features
    • Workspaces
    • Presets
    • Response Caching
    • Tool Calling
    • Structured Outputs
    • Message Transforms
    • Zero Completion Insurance
    • ZDR
    • App Attribution
    • Service Tiers
    • Sovereign AI
    • Router Metadata
    • Input & Output Logging
      • For Providers
      • Frameworks and Integrations Overview
      • Awesome OpenRouter
      • Effect AI SDK
      • Arize
      • LangChain
      • LiveKit
      • Langfuse
      • Mastra
      • OpenAI SDK
      • Anthropic Agent SDK
      • PydanticAI
      • Replit
      • TanStack AI
      • Vercel AI SDK
      • Xcode
      • Zapier
      • Infisical
LogoLogo
ModelsChatRankingsDocs
On this page
  • Effect AI SDK
Community

Effect AI SDK

Integrate OpenRouter using the Effect AI SDK
Was this page helpful?
Previous

Arize

Using OpenRouter with Arize
Next
Built with

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)