Skip to main content
Butter also works when stacked with other Chat Completions endpoints like WithMartian. WithMartian supports a CustomOpenAISDKChatProviderAdapter class which accepts the necessary base URL and builds a custom OpenAI client. Then, you can build a completion agent with the necessary headers. See it in the example below.
import os
from llm_adapters import CustomOpenAISDKChatProviderAdapter

adapter = CustomOpenAISDKChatProviderAdapter(
    base_url="https://proxy.butter.dev/v1"
)

client = adapter._get_or_create_client(
    api_key=os.getenv("OPENAI_API_KEY"), 
    client_type="sync"
)

completion = client.chat.completions.create(
  model="gpt-4",
  extra_headers={"Butter-Auth": f"Bearer {os.getenv('BUTTER_API_KEY')}"},
  messages=[{"role": "user", "content": "What is the English word for mantequilla?"}]
)

print(completion)