KoalaChat API

The KoalaChat API allows you to integrate our powerful chat capabilities into your applications. Each request to KoalaChat uses 1 chat credit.

Endpoint

POST https://koala.sh/api/gpt/

Models

The default model used is GPT-4o Mini. To specify a different model, you can use the model parameter with one of the following values:

  • gpt-4o-mini (default)
  • gpt-4o
  • claude-3.7-sonnet (requires a paid account)

Example Request

fetch("https://koala.sh/api/gpt/", {
    method: "POST",
    headers: {
        Authorization: "Bearer YOUR_API_KEY",
        "Content-Type": "application/json"
    },
    body: JSON.stringify({
        input: "what is the most popular dog breed?",
        realTimeData: true,
    })
});

Example Response

{"output": "The most popular dog breed in 2024 is the French Bulldog, retaining the top spot for the second consecutive year ([source](https://www.akc.org/most-popular-breeds/))."}

Parameters

NameTypeDescriptionRequired
inputstringYour prompt or questionYes
modelstringThe model to use (gpt-4o-mini, gpt-4o, claude-3.7-sonnet)No
inputHistoryarray of stringsPrevious user inputs for conversation historyNo
outputHistoryarray of stringsPrevious AI responses for conversation historyNo
realTimeDatabooleanWhether to include real-time data in the responseNo

Note on Conversation History: If you provide inputHistory and outputHistory, they must be of the same length. These arrays help maintain conversation context for multi-turn interactions.

Complete Example with Conversation History

// First message
const response1 = await fetch("https://koala.sh/api/gpt/", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    input: "What are the top 3 dog breeds for families?",
    realTimeData: true
  })
});

const data1 = await response1.json();
const aiResponse1 = data1.output;
console.log(aiResponse1);

// Second message (with conversation history)
const response2 = await fetch("https://koala.sh/api/gpt/", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    input: "Which of these is best for apartments?",
    inputHistory: ["What are the top 3 dog breeds for families?"],
    outputHistory: [aiResponse1],
    realTimeData: true
  })
});

const data2 = await response2.json();
console.log(data2.output);

Real-Time Data

Setting realTimeData to true allows the API to access current information from the web. This is useful for questions about current events, recent statistics, or any topic that requires up-to-date information.

If you don't need real-time data, you can omit this parameter to potentially get faster responses.

Error Handling

The API will return appropriate HTTP status codes for different error conditions:

  • 400 Bad Request: Invalid parameters or request format
  • 401 Unauthorized: Invalid or missing API key
  • 402 Payment Required: Insufficient credits
  • 429 Too Many Requests: Rate limit exceeded
  • 500 Internal Server Error: Server-side error

Best Practices

For optimal results when using the KoalaChat API:

  • Be specific in your prompts to get more accurate and relevant responses
  • Use conversation history for multi-turn interactions to maintain context
  • Enable real-time data only when you need up-to-date information
  • Consider using GPT-4o for more complex queries and Claude for nuanced responses

Need Help?

If you need additional assistance with the KoalaChat API, please contact us.