OpenAI API Drop-in

Use Metaphori compressions with any OpenAI-compatible tool or SDK. Simply change the base URL and add your compression ID.

πŸš€ Key Benefits

  • Works with all OpenAI SDKs and libraries
  • Dramatically reduce token usage (60-90% typical reduction)
  • Maintain or improve response quality
  • No code changes required - just update the endpoint

API Endpoint

Base URL:

https://ai.metaphori.dev/v1

Authentication:

Authorization: Bearer YOUR_METAPHORI_API_KEY

Using Compressions

Pass your compression ID using the mid parameter:

Method 1: Query Parameter

curl https://ai.metaphori.dev/v1/chat/completions?mid=mph_c_xxxxx \
  -H "Authorization: Bearer $METAPHORI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Explain the main function"}]
  }'

Method 2: In Model Name

Some SDKs don't support query parameters. Use this format:

{
  "model": "gpt-4o?mid=mph_c_xxxxx",
  "messages": [{"role": "user", "content": "Explain the main function"}]
}

Integration Examples

Python (OpenAI SDK)

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_METAPHORI_API_KEY",
    base_url="https://ai.metaphori.dev/v1"
)

# Method 1: Using query parameter in base_url
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Analyze this code"}],
    # Compression ID in the URL
    base_url="https://ai.metaphori.dev/v1?mid=mph_c_xxxxx"
)

# Method 2: Using model name
response = client.chat.completions.create(
    model="gpt-4o?mid=mph_c_xxxxx",
    messages=[{"role": "user", "content": "Analyze this code"}]
)

JavaScript/TypeScript

import OpenAI from 'openai';

const openai = new OpenAI({
  apiKey: 'YOUR_METAPHORI_API_KEY',
  baseURL: 'https://ai.metaphori.dev/v1',
});

// Using compression
const completion = await openai.chat.completions.create({
  model: 'gpt-4o?mid=mph_c_xxxxx',
  messages: [{ role: 'user', content: 'Explain the architecture' }],
});

cURL

# Basic request with compression
curl https://ai.metaphori.dev/v1/chat/completions?mid=mph_c_xxxxx \
  -H "Authorization: Bearer $METAPHORI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {
        "role": "user",
        "content": "What are the main components of this system?"
      }
    ],
    "temperature": 0.7
  }'

Langchain

from langchain_openai import ChatOpenAI

# Configure Metaphori as OpenAI provider
llm = ChatOpenAI(
    model="gpt-4o",
    openai_api_key="YOUR_METAPHORI_API_KEY",
    openai_api_base="https://ai.metaphori.dev/v1",
    model_kwargs={
        "extra_params": {
            "mid": "mph_c_xxxxx"  # Your compression ID
        }
    }
)

response = llm.invoke("Explain the database schema")

Supported Models

Metaphori supports a wide range of AI models from multiple providers:

Response Format

Responses are 100% compatible with OpenAI's format:

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1234567890,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Based on the compressed context..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 1523,      // Reduced from ~15,000
    "completion_tokens": 245,
    "total_tokens": 1768        // 88% reduction!
  }
}

Best Practices

πŸ”„ Keep Compressions Updated

Recreate compressions when your codebase changes significantly to maintain accuracy.

🎯 Use Specific Compressions

Create focused compressions for different parts of your codebase rather than one massive compression.

πŸ’‘ Combine with Prompts

Your prompts can reference the compression context naturally: "Based on the codebase..."

πŸ“Š Monitor Usage

Check token reduction with metaphori usage to see your savings.

Error Handling

Common errors and solutions:

Invalid Compression ID

{
  "error": {
    "message": "Compression not found: mph_c_invalid",
    "type": "invalid_request_error",
    "code": "compression_not_found"
  }
}

Verify the compression ID with metaphori list

Unauthorized

{
  "error": {
    "message": "Invalid API key",
    "type": "authentication_error",
    "code": "invalid_api_key"
  }
}

Check your Metaphori API key (starts with mph-sk-)

πŸŽ‰ You're all set!

You now know how to use Metaphori as an OpenAI drop-in replacement. Start saving tokens today!

Go to Dashboard β†’