Ai Engineering Core / LLM Ecosystem & Integrations

Routers & Abstraction Layers

As we wrap up direct provider calls, let's look at the final category β€” routers and abstraction layers.

🧐 What's the Difference?

Type

How It Works

Router

A remote service you connect to β€” it forwards your request to whichever provider you choose (e.g. OpenRouter)

Abstraction Layer

A framework running locally on your machine that translates a unified API into provider-specific calls (e.g. LiteLLM, LangChain)


πŸ”€ OpenRouter in Action

OpenRouter is one of the most popular routers β€” and you may have already been using it throughout this lab.

Why use it?

  • πŸ”‘ One API key for all providers

  • πŸ’³ Single billing account

  • πŸ§ͺ Easy model switching β€” just change the model name

  • πŸ†“ Some models are completely free

▢️ Create a new code cell and run it:

response = openrouter.chat.completions.create(model="z-ai/glm-4.5", messages=tell_a_joke)
display(Markdown(response.choices[0].message.content))

Here we used GLM-4.5 β€” an open-source model from Chinese startup ZhipuAI, accessed entirely through OpenRouter.

πŸ’‘ All model pricing, performance benchmarks, and availability are listed on openrouter.ai


🧩 LLM Abstraction Layers & Frameworks

πŸ”— LangChain

  • πŸ† The most famous LLM framework β€” often the reason people take LLM engineering courses

  • πŸ—οΈ Heavyweight abstraction layer with many powerful built-in concepts

  • πŸ”Œ Lets you swap between different model providers by importing different langchain_<provider> packages

  • πŸ“¦ Usage pattern:

    ▢️ Create a new code cell and run it:

    from langchain_openai import ChatOpenAI
    
    llm = ChatOpenAI(model="gpt-5-mini")
    response = llm.invoke(tell_a_joke)
    
    display(Markdown(response.content))
  • ⚠️ Has a steep learning curve β€” there's a lot to learn before it feels natural

  • βœ… Covered in depth in Later Sections

⚑ LiteLLM

  • πŸͺΆ Lightweight counterpart to LangChain β€” does what it says on the tin

  • 🎯 Single unified interface to call any model from any provider

  • πŸ§ͺ Usage pattern:

    ▢️ Create a new code cell and run it:

    from litellm import completion
    response = completion(model="openai/gpt-4.1", messages=tell_a_joke)
    reply = response.choices[0].message.content
    display(Markdown(reply))
  • πŸ”€ Provider format: provider/model-name

    • AWS Bedrock β†’ bedrock/...

    • Azure β†’ azure/...

    • Google Vertex β†’ vertex_ai/...

  • πŸ’° Automatically reports input tokens, output tokens, and cost per call

  • 🏭 Great for production systems β€” can track per-user token spend across models


πŸ’Έ API Cost Reality Check

  • Costs are quoted per million tokens β€” individual calls are tiny

  • Example: a full Hamlet (shakespearean play) (~53K tokens) call cost ~0.5 cents

  • Don't fear API costs for dev/testing, but do monitor unit economics at scale

  • LiteLLM makes tracking per-call costs trivially easy