Skip to main content

What are Direct API Requests?

Direct API requests mean making HTTP calls directly to Model Router’s endpoints using tools like cURL, Postman, or any HTTP client library. This is the most straightforward way to interact with the API.

Before You Start

Before making requests, check which models are available to your API key by calling the model list endpoint.

API Base URL

All requests should be sent to:
https://app.memorylake.ai

Authentication

Include your API key in the Authorization header:
Authorization: Bearer sk-your-api-key-here

Request Examples

OpenAI-Compatible Endpoint

The /v1 endpoint works with OpenAI-style requests. This is the most common way to use Model Router.
await fetch("https://app.memorylake.ai/v1/chat/completions", {
  method: "POST",
  headers: {
    "Authorization": "Bearer sk-demo123",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    model: "gpt-4o-mini",
    messages: [{ role: "user", content: "Hello, how are you?" }],
    stream: false
  })
});
Replace sk-demo123 with your actual API key. Replace gpt-4o-mini with a model that’s available to your API key. Check the model list to see available models.

Streaming Responses

To get streaming responses, set stream to true:
curl https://app.memorylake.ai/v1/chat/completions \
  -H "Authorization: Bearer sk-demo123" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [{"role": "user", "content": "Tell me a story"}],
    "stream": true
  }'

Claude Native Endpoint

If you’re using Claude models, you can use the native Claude endpoint:
await fetch("https://app.memorylake.ai/claude/v1/messages", {
  method: "POST",
  headers: {
    "Authorization": "Bearer sk-demo123",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    model: "claude-3-opus-20240229",
    max_tokens: 200,
    messages: [{ role: "user", content: "Summarize this in one sentence" }]
  })
});

Gemini Native Endpoint

For Gemini models, use the native Gemini endpoint:
await fetch("https://app.memorylake.ai/gemini/v1beta/models/gemini-1.5-pro:generateContent", {
  method: "POST",
  headers: {
    "Authorization": "Bearer sk-demo123",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    contents: [{ role: "user", parts: [{ text: "Generate a title" }] }]
  })
});

Important Notes

  1. Check Available Models: Always check which models are available to your API key before making requests. See List Available Models.
  2. Model Names: Use the exact model ID from the model list. Different API keys may have access to different models.
  3. Error Handling: If you get an error, check:
    • Is your API key correct?
    • Is the model available to your API key?
    • Do you have sufficient quota?
    • See Error Handling for more help.
  4. View Usage: After making requests, you can view your usage and billing in the console.