Skip to content

API Documentation

An OpenAI-compatible chat completion LLM API to easily integrate AI into your applications.

Quick Start

All mammouth subscribers have some credits included.

PlanStarterStandardExpert
Monthly credits2$4$10$

With the Mammouth API directly

Generates a chat completion response based on your prompt.

python
import requests
url = "https://api.mammouth.ai/v1/chat/completions"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}
data = {
    "model": "gpt-4.1",
    "messages": [
        {
            "role": "user",
            "content": "Explain the basics of machine learning"
        }
    ]
}
response = requests.post(url, headers=headers, json=data)
print(response.json())

javascript
const fetch = require("node-fetch");

async function callMammouth() {
  const url = "https://api.mammouth.ai/v1/chat/completions";
  const headers = {
    Authorization: "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
  };

  const data = {
    model: "gpt-4.1",
    messages: [
      {
        role: "user",
        content: "Create an example JavaScript function",
      },
    ],
  };

  try {
    const response = await fetch(url, {
      method: "POST",
      headers: headers,
      body: JSON.stringify(data),
    });

    const result = await response.json();
    console.log(result.choices[0].message.content);
  } catch (error) {
    console.error("Error:", error);
  }
}

callMammouth();

bash
curl -X POST https://api.mammouth.ai/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4.1",
    "messages": [
      {
        "role": "user",
        "content": "Hello, how are you doing?"
      }
    ]
  }'

➡️ Get your API key in your settings.

With OpenAI Library

python
import openai

# Configure the client to use Mammouth.ai
openai.api_base = "https://api.mammouth.ai/v1"
openai.api_key = "YOUR_API_KEY"

response = openai.ChatCompletion.create(
    model="gpt-4.1",
    messages=[
        {"role": "user", "content": "What are the benefits of renewable energy?"}
    ]
)

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

Response Format

Successful Response

json
{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gpt-4.1",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! I'm doing very well, thank you for asking. How can I help you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 19,
    "total_tokens": 31
  }
}

Streaming Response

When stream: true is set, responses are returned as Server-Sent Events:

data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4.1","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}

data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4.1","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}

data: [DONE]

Models & Pricing

ModelInput ($/M tokens)Output ($/M tokens)
gpt-4.128
gpt-4.1-mini0.41.6
gpt-4.1-nano0.10.4
gpt-4o2.510
o4-mini1.14.4
o328
mistral-large-241126
mistral-medium-30.42
mistral-small-3.2-24b-instruct0.10.3
magistral-medium-250625
codestral-25010.30.9
grok-3315
grok-3-mini0.30.5
gemini-2.5-flash0.32.5
gemini-2.5-pro2.515
deepseek-r1-052838
deepseek-v3-03240.90.9
llama-4-maverick0.220.88
llama-4-scout0.150.6
claude-3-5-haiku-202410220.84
claude-3-7-sonnet-20250219315
claude-sonnet-4-20250514315
claude-opus-4-202505141575

Prices may vary and not be up to date in this table.

📜 Usage and cost are logged in your settings.

💡 We added aliases aligned with the Mammouth app to facilitate your model selection: if you write mistral, it will use mistral-medium-3.

Error Codes

CodeDescription
400Bad Request - Missing or incorrect parameters
401Unauthorized - Invalid API key
429Too Many Requests - Rate limit exceeded
500Internal Server Error - Server-side issue
503Service Unavailable - Server temporarily unavailable

Error Response Format

json
{
  "error": {
    "message": "Invalid API key provided",
    "type": "invalid_request_error",
    "code": "invalid_api_key"
  }
}

Parameters

Required Parameters

ParameterTypeDescription
messagesarrayList of messages in the conversation
modelstringModel identifier to use

Optional Parameters

ParameterTypeDefaultDescription
temperaturenumber0.7Controls creativity (0.0 to 2.0)
max_tokensinteger2048Maximum number of tokens to generate
top_pnumber1.0Controls response diversity
streambooleanfalseReal-time response streaming

Optimization Tips

Temperature Settings

  • 0.0 - 0.3: Very consistent and predictable responses
  • 0.4 - 0.7: Balance between creativity and coherence
  • 0.8 - 1.0: More creative and varied responses

Message Structure

json
{
  "messages": [
    {
      "role": "system",
      "content": "You are an AI assistant specialized in programming."
    },
    {
      "role": "user",
      "content": "How to optimize a for loop in Python?"
    }
  ]
}

Role Types

  • system: Sets the behavior and context for the assistant
  • user: Represents messages from the user
  • assistant: Represents previous responses from the AI

Migration from OpenAI

If you're already using OpenAI's API, migrating to Mammouth.ai is simple:

  1. Change the base URL from https://api.openai.com/v1 to https://api.mammouth.ai/v1
  2. Update your API key
  3. Keep all other parameters the same

OpenAI Python Library

python
import openai

# Before
openai.api_base = "https://api.openai.com/v1"
openai.api_key = "sk-openai-key"

# After
openai.api_base = "https://api.mammouth.ai/v1"
openai.api_key = "your-mammouth-key"