Quickstart
Make your first request to the Kalle API. You need an Appmake account and a terminal, nothing else.
1. Create an API key
Open Kalle API in the Appmake console and choose Create key. Give the key a name you will recognise later, such as the app or server that will use it.
The full key is shown once. Copy it straight away: it starts with kalle_sk_. Appmake only stores a hash of it and its last four characters.
2. Save the key as an environment variable
Every example in these docs reads the key from KALLE_API_KEY:
export KALLE_API_KEY="kalle_sk_..."3. Send your first message
Pick your language. The examples use each language's standard HTTP client, so there is nothing else to install.
curl https://api.kalle.build/v1/messages \
-H "Authorization: Bearer $KALLE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kalle-turbo",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Write a tagline for a bakery that opens at 5am."
}
]
}'const response = await fetch("https://api.kalle.build/v1/messages", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.KALLE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "kalle-turbo",
max_tokens: 1024,
messages: [
{
role: "user",
content: "Write a tagline for a bakery that opens at 5am."
}
]
}),
});
console.log(await response.json());import os
import requests
response = requests.post(
"https://api.kalle.build/v1/messages",
headers={"Authorization": f"Bearer {os.environ['KALLE_API_KEY']}"},
json={
"model": "kalle-turbo",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Write a tagline for a bakery that opens at 5am."
}
]
},
)
response.raise_for_status()
print(response.json())package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
)
func main() {
body := strings.NewReader(`{
"model": "kalle-turbo",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Write a tagline for a bakery that opens at 5am."
}
]
}`)
req, _ := http.NewRequest("POST", "https://api.kalle.build/v1/messages", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KALLE_API_KEY"))
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
out, _ := io.ReadAll(res.Body)
fmt.Println(string(out))
}require "json"
require "net/http"
uri = URI("https://api.kalle.build/v1/messages")
request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer #{ENV.fetch("KALLE_API_KEY")}"
request["Content-Type"] = "application/json"
request.body = <<~JSON
{
"model": "kalle-turbo",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Write a tagline for a bakery that opens at 5am."
}
]
}
JSON
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) }
puts JSON.pretty_generate(JSON.parse(response.body))<?php
$body = <<<'JSON'
{
"model": "kalle-turbo",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Write a tagline for a bakery that opens at 5am."
}
]
}
JSON;
$ch = curl_init("https://api.kalle.build/v1/messages");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $body,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("KALLE_API_KEY"),
"Content-Type: application/json",
],
]);
echo curl_exec($ch);import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class KalleExample {
public static void main(String[] args) throws Exception {
String body = """
{
"model": "kalle-turbo",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Write a tagline for a bakery that opens at 5am."
}
]
}
""";
HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.kalle.build/v1/messages"))
.header("Authorization", "Bearer " + System.getenv("KALLE_API_KEY"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}4. Read the answer
Kalle answers with a message object. The text is in content, and usage tells you how many tokens you paid for:
{
"id": "msg_01J8Z3",
"type": "message",
"role": "assistant",
"model": "kalle-turbo",
"content": [{ "type": "text", "text": "Fresh bread before the city wakes up." }],
"stop_reason": "end_turn",
"usage": { "input_tokens": 21, "output_tokens": 11 }
}Next steps
- Choose the right model for the job in Models.
- Learn every request field in Messages endpoint.
- Show the answer while it is written with Streaming.