Supported Providers
Anthropic

Anthropic

Add the x-props-provider: anthropic header.

Call Anthropic via the OpenAI SDK

Props AI supports Anthropic queries via the OpenAI SDK.

We'll take care of creating a mapping between the OpenAI SDK and the Anthropic API, from formatting the request to handling the response.

import os
from openai import OpenAI
 
client = OpenAI(
    api_key=process.env.ANTHROPIC_API_KEY,
    base_url="https://proxy.getprops.ai",
    default_headers={
        "x-props-key": process.env.PROPS_API_KEY,
        "x-props-provider": "anthropic"
    }
)
 
chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "Say this is a test",
        }
    ],
    model="claude-3-opus-20240229",        
    max_tokens: 1024, # necessary parameter for Anthropic
    extra_headers={
        "x-props-metadata": {
            "user": "<USER_ID or STRIPE_SUBSCRIPTION_ID or INTERNAL_PROCESS_ID>"
        }
    }
)

Anthropic SDK

 
import anthropic
import json
 
client = anthropic.Anthropic(
    api_key="<ANTHROPIC_API_KEY>",
    base_url="https://proxy.getprops.ai/",
    default_headers={
        "x-props-key": "<PROPS_API_KEY>",
        "x-props-provider": "anthropic",
    }
)
 
message = client.messages.create(
    model="claude-3-opus-20240229",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Hello, Claude"}
    ],
    extra_headers= {
        "x-props-metadata": json.dumps({
            "user": "<USER_ID or STRIPE_SUBSCRIPTION_ID or INTERNAL_PROCESS_ID>",
        })
    }
)
print(message.content)

REST

curl -X POST https://proxy.getprops.ai/v1/messages \
-H "Authorization: Bearer $ANTHROPIC_API_KEY" \
-H "Content-Type: application/json" \
-H "x-props-key: $PROPS_API_KEY" \
-H "x-props-provider: anthropic" \
-H "x-props-metadata: {\"user\": \"<USER_ID or STRIPE_SUBSCRIPTION_ID or INTERNAL_PROCESS_ID>\"}" \
-H "anthropic-version: 2023-06-01" \
-d '{
    "messages": [
        {
            "role": "user",
            "content": "Write a short sentence in 5 words."
        }
    ],
    "model": "claude-3-opus-20240229",
    "max_tokens": 1024,
}'