Skip to main content

Quick Start

This guide will help you set up your working environment and make your first request to the BotHub API in just a few minutes.


Step-by-Step Guide to Getting Started

Step 1: Create an API Key​

An API key is required to authenticate your requests.

  1. Go to the BotHub for Developers section.
  2. Click the Create Key button.
  3. Save the token in a secure place. Do not publish it in public access.

Step 2: Configure the Client​

Use the official OpenAI SDK — to do this, simply specify your token and override the baseURL to the BotHub gateway address.


Step 3: Make Your First Request​

Choose the gateway you are interested in and your programming language to see an example of a basic integration.

Option A: Language Models (OpenAI Gateway)​

Use this for working with text, transcription, embeddings, and much more. Here you can use the official OpenAI client by using the API key we created and overriding the baseURL.

import OpenAI from 'openai';

const openai = new OpenAI({
apiKey: 'YOUR_BOTHUB_API_KEY',
baseURL: 'https://openai.bothub.chat/v1'
});

async function main() {
const completion = await openai.chat.completions.create({
model: 'claude-opus-5',
messages: [{ role: 'user', content: 'Hello! Tell me about yourself in three words.' }],
});

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

main();

Example response from the OpenAI gateway:​

{
"id": "gen-1779989130-XaEliNRQ9QbSu4dyJgr3",
"object": "chat.completion",
"created": 1779989130,
"model": "anthropic/claude-4.7-opus-fast-20260512",
"provider": "Anthropic",
"system_fingerprint": null,
"service_tier": "default",
"choices": [
{
"index": 0,
"logprobs": null,
"finish_reason": "stop",
"native_finish_reason": "end_turn",
"message": {
"role": "assistant",
"content": "AI assistant by Anthropic.",
"refusal": null,
"reasoning": null
}
}
],
"usage": {
"prompt_tokens": 29,
"completion_tokens": 19,
"total_tokens": 48,
"cost": 0.00372,
"is_byok": false,
"prompt_tokens_details": {
"cached_tokens": 0,
"cache_write_tokens": 0,
"audio_tokens": 0,
"video_tokens": 0
},
"cost_details": {
"upstream_inference_cost": 0.00372,
"upstream_inference_prompt_cost": 0.00087,
"upstream_inference_completions_cost": 0.00285
},
"completion_tokens_details": {
"reasoning_tokens": 0,
"image_tokens": 0,
"audio_tokens": 0
},
"speed": "fast"
}
}

Option B: Media Models (Replicate Gateway)​

Use this for generating images with Flux, Stable Diffusion, veo and many others! You can pass both generation parameters in the input object and internal bothub settings (for example, to enable metric counting or control the output format). We also proxy the response link so you can access the content without a VPN. Official provider SDKs are not supported here; requests are sent directly via HTTP.

Parameters of the bothub object​

The bothub object is passed at the top level of the request body alongside model and input. It controls the behavior of the BotHub gateway without affecting the model itself.

ParameterTypeDefaultDescription
include_usagebooleanfalseIf true — returns an usage object in the response with the number of caps used
return_base64booleanfalseIf true — returns the result in Base64 format; if false — returns a proxied link to the file
async function generateImage() {
const response = await fetch('https://bothub.chat/api/v2/replicate/v1/images/generations', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_BOTHUB_API_KEY'
},
body: JSON.stringify({
model: 'flux-2-max',
input: {
prompt: 'a white siamese cat',
output_format: 'webp',
aspect_ratio: '1:1'
},
bothub: {
include_usage: true,
return_base64: false
}
})
});

const data = await response.json();
console.log('Image URL:', data.url);
}

generateImage();

Example response from the Replicate gateway:​

{
"url": "https://32b76580-04bc-45a6-83c4-37b3a03f1877.selstorage.ru/local-timeweb/files/05218472-49fd-4ac8-be2b-f030f5ebade1.webp",
"usage": {
"bothub": {
"caps": 45000
}
}
}

SectionDescription
Prompt CachingReducing request costs through caching for OpenAI, Anthropic, Gemini, and others
Swagger / OpenAPIFull specification of all API endpoints with request examples
Models CatalogList of all available models with characteristics and pricing
For DevelopersManaging API keys and viewing usage statistics
FAQAnswers to common questions about the API, models, and billing
Telegram CommunitySupport and communication with the BotHub team
Official SupportOfficial BotHub support. We can help with payments, answer questions, and solve technical problems