OpenAI
FreeLM
API Integration
Python
TypeScript

Drop-in OpenAI Compatibility with Free Tier LLMs using FreeLM

Shihab Shahriar Antor
5 min read

TL;DR

Don't rewrite your codebase to support multiple LLM providers. FreeLM provides a perfect OpenAI SDK shim that seamlessly routes traffic to Gemini, Groq, OpenRouter, and NIM.

The API Standard

Whether we like it or not, the OpenAI API format has become the defacto standard for interacting with Large Language Models.

Almost every AI tool, framework, and agent library expects you to instantiate an OpenAI() client.

But what if you don't want to use OpenAI? What if you want to use the generous free tier of Google Gemini, or the blazing speed of Groq, or the vast array of open-source models on OpenRouter?

Normally, this means rewriting your integration layer, installing different SDKs (like @google/generative-ai), and dealing with differing response formats.

freelm changes this.

The Shim

freelm includes a drop-in compatibility layer that perfectly mimics the official OpenAI SDKs for both Python and Node.js.

It translates the OpenAI format into the native formats required by other providers, routes the request, handles any errors or rate limits, and then translates the response back into the exact JSON shape the OpenAI SDK expects.

Python Integration

Instead of:

from openai import OpenAI
client = OpenAI(api_key="sk-...")

You just change the import:

from freelm.compat import OpenAI
client = OpenAI() # It automatically pulls your free keys from the environment

Node.js / TypeScript Integration

Available via npm:

Instead of:

import OpenAI from 'openai';
const client = new OpenAI({ apiKey: '...' });

You change the import:

import { OpenAI } from 'freelm/compat';
const client = new OpenAI(); 

Full Feature Support

This isn't a hacky partial implementation. freelm's shim supports:

  • Token Streaming: Seamlessly streams chunks across different provider formats.
  • Virtual Models: You can request model: "auto" or model: "chat:fast" and freelm will dynamically pick the best free model across all your configured providers.
  • Async/Await: First-class support for modern asynchronous programming.

By using the freelm shim, you can point your existing LangChain, Vercel AI SDK, or custom agent code at a pool of free providers without changing a single line of business logic.

Written by

Shihab Shahriar Antor — AI Engineer & Founder of Shahriar Labs. Creator of LetX, QuantumSketch, and more.

Share this mission log