TeaTree API
Overview Endpoints Models Examples
View on GitHub

Unified AI Gateway

Access multiple AI providers through a single OpenAI-compatible API with model aliasing, rate limiting, and comprehensive tracking.

OpenAI
Anthropic
XAI
Fireworks
example.js
const fetchCompletion = async () => {
  const response = await fetch('https://api.teatree.chat/v1/chat/completions', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      model: 'gpt-4o',  // Use a model alias!
      messages: [{ role: 'user', content: 'Explain quantum computing' }],
      max_tokens: 150
    })
  });
  
  return await response.json();
};
Features

Everything You Need

TeaTree provides a unified interface to access models from multiple AI providers with powerful features for production deployments.

Multiple Providers

Access models from OpenAI, Anthropic, Fireworks, and XAI through a single, consistent API interface.

Advanced Thinking

Use advanced thinking for complex tasks that involve coding, math and more.

No API Key

NO API key required at all, you can just use it as simple as sending a request in your app.

Request Monitoring

Monitor all requests with detailed logs. Track token usage, model selection, and success rates.

Streaming Support

All endpoints support streaming responses, allowing for more responsive user interfaces.

Drop-in Compatibility

Follows the OpenAI API specification, making it a drop-in replacement for existing applications.

API

API Endpoints

Use these OpenAI-compatible endpoints to interact with various AI models across different providers.

GET /v1/models
Retrieve available models and aliases

Returns a list of available models and their aliases that can be used with the API.

Response Format

JSON
Response body
{
  "object": "list",
  "data": [
    {
      "id": "gpt-4o",
      "object": "model",
      "created": 1677649963,
      "owned_by": "openai",
      "provider": "openai",
      "description": "Latest GPT model with improved capabilities",
      "context_window": 8192
    },
    {
      "id": "gpt-4o-mini", // This is an alias
      "object": "model",
      "created": 1677649963,
      "owned_by": "openai",
      "provider": "openai",
      "description": "Faster and cheaper version of GPT-4o",
      "context_window": 100000
    }
    ...
  ]
}

Example Request

cURL
curl -X GET https://api.teatree.chat/v1/models \
  -H "Authorization: Bearer your-api-key"
POST /v1/chat/completions
Create a chat completion with any provider's model

This endpoint creates a completion for the chat message, compatible with various provider models.

Request Parameters

model

ID of the model or alias to use for completion.

string required
messages

A list of messages comprising the conversation so far.

array required
max_tokens

Maximum number of tokens to generate in the completion.

integer default: 100
temperature

What sampling temperature to use (higher = more creative).

number default: 0.7
stream

Whether to stream back partial progress.

boolean default: false

Example Request

cURL
curl -X POST https://api.teatree.chat/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key" \
  -d '{
  "model": "gpt-4o",
  "messages": [
    {"role": "user", "content": "Tell me about quantum computing"}
  ],
  "max_tokens": 100,
  "temperature": 0.7
}'
Models

Available Models

TeaTree provides access to various models from different providers through a unified API.

Model Library

Model ID Provider Description Context Window Supports Type
Code

Usage Examples

Here are code examples for interacting with the TeaTree API in various programming languages.

Node.js

JavaScript
Using the OpenAI Node.js client
const { OpenAI } = require('openai');

// Initialize with TeaTree API endpoint
const openai = new OpenAI({
  apiKey: 'your-api-key',
  baseURL: 'https://api.teatree.chat/v1'
});

async function main() {
  const response = await openai.chat.completions.create({
    model: 'gpt-4o', // Use a model alias
    messages: [
      { role: 'user', content: 'Explain quantum computing' }
    ],
    max_tokens: 150
  });

  console.log(response.choices[0].message.content);
}

main();

Python

Python
Using the OpenAI Python client
from openai import OpenAI

# Initialize with TeaTree API endpoint
client = OpenAI(
    api_key="your-api-key",
    base_url="https://api.teatree.chat/v1"
)

# Create a chat completion
response = client.chat.completions.create(
    model="gpt-4o-mini",  # Using a model alias
    messages=[
        {"role": "user", "content": "Write a short poem about AI"}
    ],
    max_tokens=100,
    temperature=0.7
)

# Print the response
print(response.choices[0].message.content)

Streaming Example

JavaScript
Using streaming responses
const { OpenAI } = require('openai');

const openai = new OpenAI({
  apiKey: 'your-api-key',
  baseURL: 'https://api.teatree.chat/v1'
});

async function streamResponse() {
  const stream = await openai.chat.completions.create({
    model: 'gpt-4o',
    messages: [
      { role: 'user', content: 'Write a short story' }
    ],
    stream: true,
    max_tokens: 200
  });

  // Stream the response
  for await (const chunk of stream) {
    process.stdout.write(chunk.choices[0]?.delta?.content || '');
  }
}

streamResponse();

cURL

Shell
Direct API request with cURL
# List available models
curl -X GET https://api.teatree.chat/v1/models \
  -H "Authorization: Bearer your-api-key"

# Create a chat completion
curl -X POST https://api.teatree.chat/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key" \
  -d '{
  "model": "gpt-4o",
  "messages": [
    {"role": "user", "content": "What are the key features of TeaTree API?"}
  ],
  "max_tokens": 150
}'
Advanced Features

Function Calling

Enable your AI models to call functions in your application with structured inputs and outputs.

How It Works

Function calling allows AI models to generate structured JSON that your application can use to call your own functions. This is perfect for:

  • Retrieving real-time information like weather, stocks, or sports scores
  • Performing actions like booking reservations or adding events to a calendar
  • Converting natural language to structured database queries
OpenAI Anthropic XAI
function-flow.json
{
  "model": "gpt-4o",
  "messages": [
    { "role": "user", "content": "What's the weather in Paris?" }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get weather for a location",
        "parameters": {
          "type": "object",
          "properties": {
            "location": { "type": "string" }
          },
          "required": ["location"]
        }
      }
    }
  ]
}

Weather Function

Function Definition
const weatherFunction = {
  "name": "get_weather",
  "description": "Get current weather in a location",
  "parameters": {
    "type": "object",
    "properties": {
      "location": {
        "type": "string",
        "description": "City and state or country"
      },
      "unit": {
        "type": "string",
        "enum": ["celsius", "fahrenheit"],
        "description": "Temperature unit"
      }
    },
    "required": ["location"]
  }
}

Usage Example

What's the current weather in Tokyo?
I'll check the weather in Tokyo for you.
// Function call { "name": "get_weather", "arguments": { "location": "Tokyo, Japan", "unit": "celsius" } }
The current weather in Tokyo is 22°C with partly cloudy skies. The humidity is at 65% with a light breeze from the east at 8 km/h.

Database Query Function

Function Definition
const queryFunction = {
  "name": "query_database",
  "description": "Query product database",
  "parameters": {
    "type": "object",
    "properties": {
      "category": {
        "type": "string",
        "enum": ["electronics", "clothing", "books"],
        "description": "Product category"
      },
      "price_max": {
        "type": "number",
        "description": "Maximum price"
      },
      "in_stock": {
        "type": "boolean",
        "description": "Only show in-stock items"
      }
    }
  }
}

Usage Example

Show me electronics under $100 that are in stock
I'll search for in-stock electronics under $100.
// Function call { "name": "query_database", "arguments": { "category": "electronics", "price_max": 100, "in_stock": true } }
I found 3 electronics items under $100 that are currently in stock:

1. Wireless Earbuds - $49.99
2. Bluetooth Speaker - $79.99
3. Power Bank 10000mAh - $29.99

Implementation Guide

Adding Function Calling to Your API Requests

To enable function calling in your TeaTree API requests, just add the appropriate parameters to your API calls:

  • Using the functions parameter (older format):
    {
      "model": "gpt-4o",
      "messages": [...],
      "functions": [{...}],
      "function_call": "auto" // or {"name": "function_name"}
    }
  • Using the tools parameter (newer format):
    {
      "model": "gpt-4o",
      "messages": [...],
      "tools": [
        {"type": "function", "function": {...}}
      ],
      "tool_choice": "auto" // or {"type": "function", "function": {"name": "function_name"}}
    }
Important: Make sure your model supports function calling. You can check in the Models section to see which models have this capability.
TeaTree API Status