Get started

Inference Quickstart

Make your first request and show an ad when Koah requests one.

Koah Free Inference gives your app access to leading open-source models, with token costs funded by ads. Use a familiar client SDK to generate content, then show an ad if Koah returns an ad ID. Not every response includes an ad. Choose from the supported models.

Set your API key

Use your Koah inference key on the server. You will also need the public publisher ID for the same app. See Rate Limits for request limits and how to request more capacity.

export KOAH_INFERENCE_API_KEY="YOUR_KOAH_INFERENCE_KEY"

Run inference

Call a model using the OpenAI SDK. This example uses sail/DeepSeek-V4.1-Flash-1017-free, but you can swap in any supported model.

To create a chat completion:

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://inference.koah.ai/v1",
    api_key=os.environ["KOAH_INFERENCE_API_KEY"],
)

raw = client.chat.completions.with_raw_response.create(
    model="sail/DeepSeek-V4.1-Flash-1017-free",
    messages=[{"role": "user", "content": "What is inference in machine learning?"}],
)
response = raw.parse()

print("Generated Content:", response.choices[0].message.content)
print("Ad ID:", raw.headers.get("X-Koah-Ad-Id"))

Success looks like this:

Generated Content: Inference is the process of using a trained model to make predictions or generate output from new input.
Ad ID: ad_example_123

The ad ID appears only when Koah requests an ad. Otherwise, the header is absent; Python prints None and TypeScript prints null.

Render the ad

Choose the Koah Ads SDK for your app's environment. Use your app's public publisher ID and keep the ad beside the answer.

API preview: The ad-ID rendering calls below are proposed and are not yet available in released SDKs.

Follow the JavaScript setup guide.

<div id="koah-ad-slot"></div>
<script defer src="https://app.koah.ai/js?token=YOUR_PUBLISHER_ID"></script>
<script defer src="/chat.js"></script>

In chat.js, pass the ad ID from your server response to the renderer:

Proposed API

if (adId) {
  await window.koah.displayAd(adId, {
    target: document.getElementById('koah-ad-slot'),
  })
}

Koah handles ad rendering and measurement. You pass only the ad ID and visible placement.

A response without an ad ID needs no display call. Keep the answer visible if ad delivery fails. See Ads and Validation for the full requirements.

Next steps

Was this helpful?