Skip to main content
Both OpenAI-compatible and Anthropic-compatible protocols are supported for text generation.

OpenAI-Compatible Interface

For features not covered here, refer to the OpenAI API Reference.

Message Roles

RolePurposeExample
systemSets the model’s behavior and persona”You are an experienced software engineer.”
userThe end user’s input”How do I reverse a string in Python?”
assistantPrior model responses, for multi-turn context”You can use s[::-1] or ''.join(reversed(s)).”

Basic Conversation

from openai import OpenAI

client = OpenAI(
    base_url="https://api.ephone.ai/v1",
    api_key="API_KEY",
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)

print(response.choices[0].message.content)

Streaming

from openai import OpenAI

client = OpenAI(
    base_url="https://api.ephone.ai/v1",
    api_key="API_KEY",
)

stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Write a short poem about spring."}],
    stream=True,
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Tool Calling (Function Calling)

For more details, see the OpenAI tool use guide.
from openai import OpenAI

client = OpenAI(
    base_url="https://api.ephone.ai/v1",
    api_key="API_KEY",
)

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get the current weather for a city",
            "parameters": {
                "type": "object",
                "properties": {
                    "city": {"type": "string", "description": "City name"}
                },
                "required": ["city"],
            },
        },
    }
]

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "What's the weather in London?"}],
    tools=tools,
)

print(response.choices[0].message)

Response API

The OpenAI Responses API is supported for OpenAI models. See the OpenAI Responses API docs for usage details.
  1. Set OPENAI_BASE_URL to https://api.ephone.ai/v1
  2. Set OPENAI_API_KEY to your API key
  3. Some parameters (presence_penalty, frequency_penalty, logit_bias, etc.) may be ignored by certain models
  4. The legacy function_call parameter is deprecated — use tools instead

Anthropic-Compatible Interface

For features not covered here, refer to the Anthropic API Reference.

Basic Conversation

import anthropic

client = anthropic.Anthropic(
    base_url="https://api.ephone.ai/anthropic",
    api_key="API_KEY",
)

message = client.messages.create(
    model="claude-opus-4-5-20251101",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello!"}]
)

print(message.content[0].text)

Streaming

import anthropic

client = anthropic.Anthropic(
    base_url="https://api.ephone.ai/anthropic",
    api_key="API_KEY",
)

with client.messages.stream(
    model="claude-opus-4-5-20251101",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a short poem about spring."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

Tool Calling

For more details, see the Anthropic tool use guide.
import anthropic

client = anthropic.Anthropic(
    base_url="https://api.ephone.ai/anthropic",
    api_key="API_KEY",
)

tools = [
    {
        "name": "get_weather",
        "description": "Get the current weather for a city",
        "input_schema": {
            "type": "object",
            "properties": {
                "city": {"type": "string", "description": "City name"}
            },
            "required": ["city"],
        },
    }
]

message = client.messages.create(
    model="claude-opus-4-5-20251101",
    max_tokens=1024,
    tools=tools,
    messages=[{"role": "user", "content": "What's the weather in London?"}],
)

print(message.content)
  1. Set ANTHROPIC_BASE_URL to https://api.ephone.ai/anthropic
  2. Set ANTHROPIC_API_KEY to your API key

OpenAI Official Docs

OpenAI Chat Completions API reference

Anthropic Official Docs

Anthropic Messages API reference