Skip to main content

SDK Integration for Developers

The LeanMCP AI Gateway works with any OpenAI-compatible SDK or library. Simply change the base URL and API key to route requests through the gateway.
Key Insight: Any library that supports a custom baseURL or base_url parameter can use the LeanMCP AI Gateway.

Prerequisites

1

Get Credits

Purchase credits at leanmcp.com
2

Create API Key

Create an API key at leanmcp.com/api-keys with SDK permissions

Gateway Endpoints


Official SDKs

OpenAI SDK

Anthropic SDK

Streaming


Framework Integrations

LangChain

Vercel AI SDK

LlamaIndex


Adding Request Context

For better tracking and analytics, add custom headers to your requests:
These headers appear in your dashboard and enable:
  • Per-user usage tracking and limits
  • Session-based request grouping
  • Feature-level analytics
  • Source attribution

OpenAI-Compatible Libraries

Any library that supports a custom base URL works with the LeanMCP AI Gateway:

Generic Pattern


Environment Setup

Multiple Environments


Error Handling


Benefits for Developers

Unified Logging

All AI requests logged in one dashboard

User Tracking

Track usage per user with custom headers

Cost Attribution

Know which features drive AI costs

A/B Testing

Test different models and prompts

Security

Block malicious users and sensitive data

Rate Limiting

Set limits per user or globally

Next Steps

Security Features

Block users and protect sensitive data

Token Optimization

A/B testing and cost reduction

Observability

Monitor all requests

For Developers

Advanced developer features