Skip to main content

What are MVP Examples?

These are minimal, complete, and runnable code examples that you can copy and use immediately. Each example is self-contained and shows the essential code needed to make API calls to Model Router.
Before running these examples, make sure you have:
  1. Created an API key (see Create API Key)
  2. Checked which models are available (see List Available Models)
  3. Replaced sk-demo123 with your actual API key
  4. Replaced the model name with one available to your API key

Python Examples

Recommended: The OpenAI official SDK is the easiest way to use Model Router. You only need to change the base_url parameter - everything else works exactly the same as with OpenAI’s API.

Installation

Complete Example

Running the Example

  1. Save the code to a file (e.g., chat.py)
  2. Install dependencies: pip install openai
  3. Replace api_key and model with your values
  4. Run: python chat.py
Key Point: The only difference from using OpenAI’s API directly is setting base_url="https://app.memorylake.ai/v1". All other code remains exactly the same!

Using Environment Variables

You can also use environment variables for better security:

Using requests Library (Alternative)

If you prefer using the requests library directly:

Installation

Complete Example

Running the Example

  1. Save the code to a file (e.g., chat.py)
  2. Install dependencies: pip install requests
  3. Replace API_KEY and MODEL with your values
  4. Run: python chat.py

TypeScript/JavaScript Examples

Recommended: The OpenAI official SDK works seamlessly with Model Router. You only need to change the baseURL parameter - everything else works exactly the same as with OpenAI’s API.

Installation

For TypeScript projects, you may also want to install type definitions:

Complete Example (TypeScript)

Complete Example (JavaScript)

Running the Example

  1. Save the code to a file (e.g., chat.ts or chat.mjs)
  2. Install dependencies: npm install openai
  3. Replace apiKey and model with your values
  4. Run:
    • TypeScript: npx ts-node chat.ts (or compile first with tsc)
    • JavaScript: node chat.mjs (or node chat.js if using CommonJS)
Key Point: The only difference from using OpenAI’s API directly is setting baseURL: "https://app.memorylake.ai/v1". All other code remains exactly the same!

Using Environment Variables

You can also use environment variables for better security:

Streaming Examples

Python - Using OpenAI Official SDK

For streaming responses with the OpenAI SDK:

Python - Using requests Library

For streaming responses with the requests library:

TypeScript/JavaScript - Using OpenAI Official SDK

For streaming responses with the OpenAI SDK:

Other Official SDKs

Model Router is compatible with many official SDKs from different AI platforms. Most of them only require configuring the API_KEY and BASE_URL to work with Model Router.
Key Point: For most official SDKs, you only need to:
  1. Set the baseURL or base_url to https://app.memorylake.ai/v1 (or the corresponding endpoint)
  2. Use your Model Router API key as the apiKey or api_key
  3. Everything else works exactly the same as with the original platform’s API

Anthropic Claude SDK

The official Anthropic Claude SDK supports Python, TypeScript/JavaScript, Java, Go, C#, Ruby, and PHP. Example (Python):
Example (TypeScript):
Documentation: Anthropic Client SDKs

Vercel AI SDK

The Vercel AI SDK provides a unified interface for multiple AI providers, including OpenAI, Anthropic, Google, and more. Example:
Documentation: Vercel AI SDK Providers

Google Gemini SDK

The official Google Gemini SDK supports Python, Node.js, and other languages. Example (Python):
Documentation: Google Gemini API Migration Guide

General Pattern

Most official SDKs follow a similar pattern:
  1. Install the SDK: Use the official package manager (pip, npm, etc.)
  2. Configure the client: Set baseURL/base_url to Model Router’s endpoint
  3. Set API key: Use your Model Router API key
  4. Use normally: All other code remains the same
Common Endpoints:
  • OpenAI-compatible: https://app.memorylake.ai/v1
  • Claude native: https://app.memorylake.ai/claude
  • Gemini native: https://app.memorylake.ai/gemini
Before using any SDK, make sure to check which models are available to your API key by calling the model list endpoint.

Next Steps

  1. Test Your Code: Run one of the examples above with your API key
  2. Check Your Usage: See View Usage and Billing to monitor your API calls
  3. Handle Errors: Learn about Error Handling if you encounter issues
  4. Explore More: Check out Direct API Requests for more advanced usage