Docs
Cookbook

SDKs and libraries

Call the Tase API from JavaScript, Python, Swift, or plain curl. No dedicated SDK required — any OpenAI-compatible client works with a base URL change.

Tase does not ship its own SDK, and it does not need one. The API follows the OpenAI chat completions wire format exactly, so every mature OpenAI-compatible client library works against it out of the box. Point the client at https://api.tase.app/v1, authenticate with your Tase key, and use tase-8b as the model name.

Why no official SDK

An OpenAI-compatible API means you inherit years of battle-tested client libraries for free: retries, timeouts, streaming helpers, and type definitions are already solved. A separate Tase SDK would only duplicate them.

Set your key once

Every example on this page reads the API key from the environment. Export it once in your shell (or put it in your deployment secrets) and never write the raw tase_sk_... string into source code:

export TASE_API_KEY="tase_sk_your_key_here"

curl

The zero-dependency option. Useful for a first smoke test and for debugging exactly what goes over the wire.

curl https://api.tase.app/v1/chat/completions \
  -H "Authorization: Bearer $TASE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "tase-8b",
    "messages": [
      { "role": "user", "content": "Give me a one-line productivity tip." }
    ]
  }'

JavaScript / TypeScript

Use the official openai npm package and override baseURL. The package ships its own TypeScript types, so completions are fully typed with no extra setup.

npm install openai
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env.TASE_API_KEY, // tase_sk_...
  baseURL: 'https://api.tase.app/v1',
});

const completion = await client.chat.completions.create({
  model: 'tase-8b',
  messages: [
    { role: 'system', content: 'You are a concise assistant.' },
    { role: 'user', content: 'Give me a one-line productivity tip.' },
  ],
});

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

Python

Use the official openai package from PyPI and override base_url. Everything else — streaming, tool calls, async — works the same as it would against any compatible endpoint.

pip install openai
import os

from openai import OpenAI

client = OpenAI(
    api_key=os.environ["TASE_API_KEY"],  # tase_sk_...
    base_url="https://api.tase.app/v1",
)

completion = client.chat.completions.create(
    model="tase-8b",
    messages=[
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": "Give me a one-line productivity tip."},
    ],
)

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

Swift

For Swift, plain URLSession with Codable models is all you need — no third-party dependency. This example is a complete command-line program: define the request and response shapes, POST, decode.

import Foundation

struct ChatMessage: Codable {
    let role: String
    let content: String
}

struct ChatRequest: Codable {
    let model: String
    let messages: [ChatMessage]
}

struct ChatResponse: Codable {
    struct Choice: Codable {
        struct Message: Codable { let content: String? }
        let message: Message
    }
    let choices: [Choice]
}

enum TaseAPIError: Error {
    case missingKey
    case badResponse
}

func chat(_ prompt: String) async throws -> String {
    guard let apiKey = ProcessInfo.processInfo.environment["TASE_API_KEY"] else {
        throw TaseAPIError.missingKey
    }

    var request = URLRequest(url: URL(string: "https://api.tase.app/v1/chat/completions")!)
    request.httpMethod = "POST"
    request.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")
    request.setValue("application/json", forHTTPHeaderField: "Content-Type")
    request.httpBody = try JSONEncoder().encode(
        ChatRequest(
            model: "tase-8b",
            messages: [ChatMessage(role: "user", content: prompt)]
        )
    )

    let (data, response) = try await URLSession.shared.data(for: request)
    guard (response as? HTTPURLResponse)?.statusCode == 200 else {
        throw TaseAPIError.badResponse
    }

    let completion = try JSONDecoder().decode(ChatResponse.self, from: data)
    return completion.choices.first?.message.content ?? ""
}

let reply = try await chat("Give me a one-line productivity tip.")
print(reply)

Never ship a key inside a client app

The Swift example reads the key from the environment because it is meant for server-side Swift or a local tool. In a shipped iOS or macOS app, the key would be extractable from the binary — route requests through your own backend instead and keep the key there.

Next: build a working assistant

A complete tool-calling loop in Node.js — from user message to executed tool to final answer.

Build an assistant