### Set up Python Virtual Environment and Install Dependencies Source: https://bothub.chat/api/documentation/ru/integration/libre-chat Create and activate a Python virtual environment (version 3.11 or 3.12 recommended) and install the project dependencies using pip. Ensure Python is added to your PATH. ```bash py -3.12 -m venv C:\rag_env && C:\rag_env\Scripts\activate && cd /d D:\rag_api && pip install -r requirements.txt ``` -------------------------------- ### Install MongoDB on Linux Source: https://bothub.chat/api/documentation/ru/integration/libre-chat Install MongoDB using the apt package manager on Linux systems. ```bash sudo apt install -y mongodb ``` -------------------------------- ### Install uv on Windows Source: https://bothub.chat/api/documentation/ru/integration/open-webui Use this command to install the 'uv' program on Windows. Ensure PowerShell's execution policy allows script execution. ```powershell powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 \| iex" ``` -------------------------------- ### cURL Examples for OpenAI API Source: https://bothub.chat/api/documentation/ru/swagger Examples for listing available models and generating responses using cURL. Ensure you replace '<ваш токен доступа>' with your actual token. ```bash # Список доступных моделей curl 'https://openai.bothub.chat/v1/models' \ -H 'Authorization: Bearer <ваш токен доступа>' # Генерация ответа curl 'https://openai.bothub.chat/v1/chat/completions' \ -H 'Authorization: Bearer <ваш токен доступа>' \ -H 'Content-Type: application/json' \ -d '{ "model": "gpt-5-mini", "messages": [{"role": "user", "content": "Привет!"}] }' ``` -------------------------------- ### Start RAG Server Command Source: https://bothub.chat/api/documentation/ru/integration/libre-chat Use this command to start the RAG server. It will download the embedding model on the first run. Ensure you are in the correct directory and have the environment activated. ```bash cd /d D:\rag_api && C:\rag_env\Scripts\python.exe ‑m uvicorn main:app ‐host 0.0.0.0 ‐port 8000 ``` -------------------------------- ### Start LibreChat Backend and Open in Browser (Linux) Source: https://bothub.chat/api/documentation/ru/integration/libre-chat A shell script to start the LibreChat backend and automatically open the application in the default web browser on Linux. ```bash #!/bin/bash cd ~/LibreChat npm run backend & sleep 2 xdg-open http://localhost:3080 ``` -------------------------------- ### Install Open WebUI with Python 3.11 Source: https://bothub.chat/api/documentation/ru/integration/open-webui Installs Open WebUI using Python 3.11. The '--with itsdangerous' flag is included to bypass a known bug. This command sets the data directory to 'C:\open-webui\data'. ```powershell powershell -c "\$env:DATA_DIR='C:\\open-webui\\data'; uvx --python 3.11 --with itsdangerous open-webui@latest serve" ``` -------------------------------- ### List All Configured Models Source: https://bothub.chat/api/documentation/ru/integration/openclaw Display a list of all models configured within OpenClaw. This command helps in verifying your setup. ```bash openclaw models list ``` -------------------------------- ### Install MongoDB Community Edition (Mac) Source: https://bothub.chat/api/documentation/ru/integration/libre-chat Install MongoDB Community Edition using Homebrew on Mac systems. ```bash brew tap mongodb/brew && brew install mongodb-community ``` -------------------------------- ### Get Replicate Models Source: https://bothub.chat/api/documentation/ru/replicate-api Use this command to retrieve a list of all supported models available through the Replicate API. Ensure you replace `` with your actual access token. ```bash curl https://bothub.chat/api/v2/replicate/v1/models \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ' ``` -------------------------------- ### Multi-turn Dialogue Example Source: https://bothub.chat/api/documentation/ru/text_generation/responses Demonstrates how to maintain conversation context by sending the full dialogue history in subsequent requests to the /v1/responses endpoint. ```APIDOC ## POST /v1/responses - Multi-turn Dialogue ### Description This endpoint is used to generate responses from a model. For multi-turn dialogues, the entire conversation history must be included in the `input` field to maintain context, as the API is stateless. ### Method POST ### Endpoint /v1/responses ### Request Body - **model** (string) - Required - The model to use for generation (e.g., "gpt-4.1-mini"). - **input** (array) - Required - An array of message objects representing the conversation history. - Each message object should have: - **type** (string) - Required - Must be "message". - **role** (string) - Required - The role of the message sender (e.g., "user", "assistant"). - **content** (array) - Required - An array of content objects. - For user messages, content type is typically `input_text`. - For assistant messages, content type is typically `output_text`. - **id** (string) - Required for assistant messages - A unique identifier for the assistant's message. - **status** (string) - Required for assistant messages - The status of the assistant's message (e.g., "completed"). - **max_output_tokens** (integer) - Optional - The maximum number of tokens to generate. ### Request Example (TypeScript) ```typescript // First request const firstResponse = await fetch( "https://openai.bothub.chat/v1/responses", { method: "POST", headers: { Authorization: "Bearer YOUR_BOTHUB_API_KEY", "Content-Type": "application/json", }, body: JSON.stringify({ model: "gpt-4.1-mini", input: [ { type: "message", role: "user", content: [ { type: "input_text", text: "What is the capital of France?", }, ], }, ], max_output_tokens: 9000, }), } ); const firstResult = await firstResponse.json(); // Second request - include previous conversation const secondResponse = await fetch( "https://openai.bothub.chat/v1/responses", { method: "POST", headers: { Authorization: "Bearer YOUR_BOTHUB_API_KEY", "Content-Type": "application/json", }, body: JSON.stringify({ model: "gpt-4.1-mini", input: [ { type: "message", role: "user", content: [ { type: "input_text", text: "What is the capital of France?", }, ], }, { type: "message", role: "assistant", id: "msg_abc123", status: "completed", content: [ { type: "output_text", text: "The capital of France is Paris.", annotations: [], }, ], }, { type: "message", role: "user", content: [ { type: "input_text", text: "What is the population of that city?", }, ], }, ], max_output_tokens: 9000, }), } ); const secondResult = await secondResponse.json(); ``` ### Request Example (Python) ```python import requests # First request first_response = requests.post( 'https://openai.bothub.chat/v1/responses', headers={ 'Authorization': 'Bearer YOUR_BOTHUB_API_KEY', 'Content-Type': 'application/json', }, json={ 'model': 'gpt-4.1-mini', 'input': [ { 'type': 'message', 'role': 'user', 'content': [ { 'type': 'input_text', 'text': 'What is the capital of France?', }, ], }, ], 'max_output_tokens': 9000, } ) first_result = first_response.json() # Second request - include previous conversation second_response = requests.post( 'https://openai.bothub.chat/v1/responses', headers={ 'Authorization': 'Bearer YOUR_BOTHUB_API_KEY', 'Content-Type': 'application/json', }, json={ 'model': 'gpt-4.1-mini', 'input': [ { 'type': 'message', 'role': 'user', 'content': [ { 'type': 'input_text', 'text': 'What is the capital of France?', }, ], }, { 'type': 'message', 'role': 'assistant', 'id': 'msg_abc123', 'status': 'completed', 'content': [ { 'type': 'output_text', 'text': 'The capital of France is Paris.', 'annotations': [] } ] }, { 'type': 'message', 'role': 'user', 'content': [ { 'type': 'input_text', 'text': 'What is the population of that city?', }, ], }, ], 'max_output_tokens': 9000, } ) second_result = second_response.json() ``` ### Notes - The `id` and `status` fields are mandatory for any messages with the role `assistant` included in the dialogue history. - Always include the complete dialogue history in each request. The API does not store previous messages, so context must be managed on the client side. ``` -------------------------------- ### Create Open WebUI Shortcut for Auto-Start Source: https://bothub.chat/api/documentation/ru/integration/open-webui Creates a shortcut to automatically start the Open WebUI server and open it in the browser. Adjust the 'Start-Sleep' duration if needed. This command sets the data directory and then launches the server and browser. ```powershell powershell -c "$env:DATA_DIR='C:\\open-webui\\data'; Start-Process powershell -ArgumentList 'uvx --python 3.11 open-webui@latest serve'; Start-Sleep -Seconds 3; Start-Process http://localhost:8080/" ``` -------------------------------- ### Example API Response for Models Source: https://bothub.chat/api/documentation/ru/api This is an example of the JSON response structure you can expect when requesting available models from the BotHub API. ```json { "object": "list", "data": [ { "id": "gpt-5-mini", "created": 1735689600, "object": "model", "owned_by": "openai" } ] } ``` -------------------------------- ### Synchronous Chat Completion in Python Source: https://bothub.chat/api/documentation/ru/text_generation/chat-completions This Python snippet demonstrates synchronous text generation. The 'openai' library must be installed and the client initialized. ```python chat_completion = client.chat.completions.create( messages=[ { 'role': 'user', 'content': 'Say this is a test', } ], model='gpt-5-mini', ) ``` -------------------------------- ### Simple Text Input Source: https://bothub.chat/api/documentation/ru/text_generation/responses This section demonstrates how to use the API with a simple string input for text generation. Examples are provided for TypeScript, Python, and cURL. ```APIDOC ## POST /v1/responses (Simple Text Input) ### Description Generates text using a simple string as input. ### Method POST ### Endpoint https://openai.bothub.chat/v1/responses ### Request Body - **model** (string) - Required - The model to use for generation (e.g., "gpt-4.1-mini"). - **input** (string) - Required - The text prompt for generation. - **max_output_tokens** (integer) - Optional - The maximum number of tokens to generate. ### Request Example (cURL) ```curl curl -X POST https://openai.bothub.chat/v1/responses \ -H "Authorization: Bearer YOUR_BOTHUB_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4.1-mini", "input": "What is the meaning of life?", "max_output_tokens": 9000 }' ``` ### Response #### Success Response (200) - **id** (string) - Unique identifier for the response. - **object** (string) - Type of the object (e.g., "response"). - **created_at** (integer) - Timestamp of creation. - **model** (string) - The model used for generation. - **output** (array) - An array of generated messages. - **usage** (object) - Token usage information. - **status** (string) - Status of the generation (e.g., "completed"). #### Response Example ```json { "id": "resp_1234567890", "object": "response", "created_at": 1234567890, "model": "gpt-4.1-mini", "output": [ { "type": "message", "id": "msg_abc123", "status": "completed", "role": "assistant", "content": [ { "type": "output_text", "text": "The meaning of life is a philosophical question that has been pondered for centuries...", "annotations": [] } ] } ], "usage": { "input_tokens": 12, "output_tokens": 45, "total_tokens": 57 }, "status": "completed" } ``` ``` -------------------------------- ### Initialize OpenAI Client with BotHub Base URL (Python) Source: https://bothub.chat/api/documentation/ru/configuration Initialize the OpenAI client for Python using your BotHub access token and the specified base URL. This setup is required for all API interactions. ```python from openai import OpenAI client = OpenAI( api_key='', base_url='https://openai.bothub.chat/v1' ) ``` -------------------------------- ### Initialize OpenAI Client with BotHub Base URL (JavaScript) Source: https://bothub.chat/api/documentation/ru/configuration Initialize the OpenAI client for JavaScript using your BotHub access token and the specified base URL. This setup is required for all API interactions. ```javascript import OpenAI from 'openai'; const openai = new OpenAI({ apiKey: '', baseURL: 'https://openai.bothub.chat/v1' }); ``` -------------------------------- ### System Message Caching (Default TTL) Source: https://bothub.chat/api/documentation/ru/prompt-caching Example of caching system messages with the default TTL of 5 minutes. Use this for system-level instructions that don't change frequently. ```json { "messages": [ { "role": "system", "content": [ { "type": "text", "text": "You are a historian studying the fall of the Roman Empire. You know the following book very well:" }, { "type": "text", "text": "HUGE TEXT BODY", "cache_control": { "type": "ephemeral" } } ] }, { "role": "user", "content": [ { "type": "text", "text": "What triggered the collapse?" } ] } ] } ``` -------------------------------- ### Structured Message Input with TypeScript Source: https://bothub.chat/api/documentation/ru/text_generation/responses This TypeScript example shows how to send structured messages for more complex dialogues. The input is an array of message objects. ```typescript const response = await fetch("https://openai.bothub.chat/v1/responses", { method: "POST", headers: { Authorization: "Bearer YOUR_BOTHUB_API_KEY", "Content-Type": "application/json", }, body: JSON.stringify({ model: "gpt-4.1-mini", input: [ { type: "message", role: "user", content: [ { type: "input_text", text: "Tell me a joke about programming", }, ], }, ], max_output_tokens: 9000, }), }); const result = await response.json(); ``` -------------------------------- ### JavaScript Speech Generation Source: https://bothub.chat/api/documentation/ru/speech_generation Example of generating speech using the OpenAI SDK in JavaScript. This code snippet demonstrates how to create speech, convert it to a buffer, and save it to a file. ```APIDOC ## JavaScript Speech Generation ### Description Generates speech from input text using the OpenAI SDK and saves it as an MP3 file. ### Method `openai.audio.speech.create()` ### Parameters - **model** (string) - Required - The model to use for speech generation (e.g., "tts-1-hd"). - **voice** (string) - Required - The voice to use for speech generation (e.g., "nova"). - **input** (string) - Required - The text to convert to speech. - **response_format** (string) - Optional - The format of the output audio (e.g., "mp3"). - **speed** (number) - Optional - The speaking rate of the generated audio (0.25 to 4.0). ### Request Example ```javascript async function main() { const req = await openai.audio.speech.create({ model: "tts-1-hd", voice: "nova", input: "This is a test speech", response_format: "mp3", speed: 0.8 }); const buffer = Buffer.from(await req.arrayBuffer()); await fs.promises.writeFile('output.mp3', buffer); } main(); ``` ### Response - **Audio Data** - The generated speech audio data, saved to a file. ``` -------------------------------- ### Get Available Models (OpenAI Format) - Python Source: https://bothub.chat/api/documentation/ru/api This Python snippet uses the requests library to retrieve a list of available models. Remember to substitute '' with your valid access token. ```python models = requests.get( 'https://openai.bothub.chat/v1/models', headers={ 'Content-Type': 'application/json', 'Authorization': 'Bearer ', }, ).json() ``` -------------------------------- ### Build pgvector Extension Source: https://bothub.chat/api/documentation/ru/integration/libre-chat Build the pgvector extension using nmake within the VS 2022 Native Tools Command Prompt. Ensure PostgreSQL is installed and accessible. ```bash set "PGROOT=C:\Program Files\PostgreSQL\17" && cd /d D:\pgvector && nmake /F Makefile.win && nmake /F Makefile.win install ``` -------------------------------- ### Python Speech Generation Source: https://bothub.chat/api/documentation/ru/speech_generation Example of generating speech using the OpenAI client library in Python. This code snippet shows how to define parameters and stream the generated speech directly to a file. ```APIDOC ## Python Speech Generation ### Description Generates speech from input text using the OpenAI client library in Python and streams it to an MP3 file. ### Method `client.audio.speech.create(**params)` ### Parameters - **model** (string) - Required - The model to use for speech generation (e.g., "tts-1-hd"). - **voice** (string) - Required - The voice to use for speech generation (e.g., "nova"). - **input** (string) - Required - The text to convert to speech. - **response_format** (string) - Optional - The format of the output audio (e.g., "mp3"). - **speed** (number) - Optional - The speaking rate of the generated audio (0.25 to 4.0). ### Request Example ```python params = { "model": "tts-1-hd", "voice": "nova", "input": "This is a test speech", "response_format": "mp3", "speed": 0.8 } speech_file_path = Path(__file__).parent / "output.mp3" req = client.audio.speech.create(**params) req.stream_to_file(speech_file_path) ``` ### Response - **Audio Data** - The generated speech audio data, streamed directly to the specified file path. ``` -------------------------------- ### Create Chat Completion with Base64 Encoded Image (Python) Source: https://bothub.chat/api/documentation/ru/vision This Python code demonstrates how to encode a local image file into a Base64 string and include it in a chat completion request. You need to have the OpenAI client library installed. ```python def encode_image(image_path): with open(image_path, "rb") as image_file: return base64.b64encode(image_file.read()).decode("utf-8") image_path = "/path/to/file.jpg" base64_image = encode_image(image_path) res = client.chat.completions.create( model="gpt-4o", messages=[ { "role": "user", "content": [ {"type": "text", "text": "What’s in this image?"}, { "type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{base64_image}"}, }, ], } ], ) ``` -------------------------------- ### Gemini 2.5 Flash Image (Nano Banana) Source: https://bothub.chat/api/documentation/ru/image_generation This section details how to generate images using the Gemini 2.5 Flash model, with examples provided for JavaScript, Python, and cURL. ```APIDOC ## Gemini 2.5 Flash Image Generation ### Description Generates an image based on a user's text prompt using the Gemini 2.5 Flash model. ### Method POST ### Endpoint /v1/chat/completions ### Parameters #### Request Body - **model** (string) - Required - The model to use, e.g., 'gemini-2.5-flash-image'. - **messages** (array) - Required - An array of message objects. - **role** (string) - Required - The role of the message sender ('user'). - **content** (string) - Required - The text prompt for image generation. ### Request Example (JavaScript) ```javascript import OpenAI from 'openai'; import fs from 'fs'; // Client configuration - see /configuration page const openai = new OpenAI(); async function generateWithGemini() { const response = await openai.chat.completions.create({ model: 'gemini-2.5-flash-image', messages: [ { role: 'user', content: 'Создай картинку с нано-бананом в шикарном ресторане' } ] }); // Extracting images from the response const message = response.choices[0].message; if (message.images && message.images.length > 0) { // Images are returned in data URL format message.images.forEach((image, index) => { const imageUrl = image.image_url.url; const base64Data = imageUrl.split(',')[1]; // Extract base64 from data URL const buffer = Buffer.from(base64Data, 'base64'); const filename = `gemini_generated_${index}.png`; fs.writeFileSync(filename, buffer); console.log(`Image ${index + 1} saved to ${filename}`); }); } } generateWithGemini(); ``` ### Request Example (Python) ```python from openai import OpenAI import base64 # Client configuration - see /configuration page client = OpenAI() response = client.chat.completions.create( model='gemini-2.5-flash-image', messages=[ { 'role': 'user', 'content': 'Создай картинку с нано-бананом в шикарном ресторане' } ] ) # Extracting images from the response message = response.choices[0].message if hasattr(message, 'images') and message.images: # Images are returned in data URL format for index, image in enumerate(message.images): image_url = image.image_url.url base64_data = image_url.split(',')[1] # Extract base64 from data URL image_data = base64.b64decode(base64_data) filename = f'gemini_generated_{index}.png' with open(filename, 'wb') as f: f.write(image_data) print(f'Image {index + 1} saved to {filename}') ``` ### Request Example (cURL) ```bash curl https://openai.bothub.chat/v1/chat/completions \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ' \ -d { "model": "gemini-2.5-flash-image", "messages": [ { "role": "user", "content": "Создай картинку с нано-бананом в шикарном ресторане" } ] } ``` ### Response Images are returned in the response, typically as data URLs, which can be decoded to obtain image files. ``` -------------------------------- ### Connect to PostgreSQL and Create Database Source: https://bothub.chat/api/documentation/ru/integration/libre-chat Connect to your PostgreSQL instance using psql and create a new database and user for RAG. This user will have superuser privileges. ```bash "c:\Program Files\PostgreSQL\17\bin\psql.exe" -U postgres -h localhost -p 5432 ``` ```sql CREATE DATABASE rag_db; CREATE USER rag_user WITH PASSWORD 'rag_password_123456' SUPERUSER; ``` -------------------------------- ### Create RAG Server Shortcut Source: https://bothub.chat/api/documentation/ru/integration/libre-chat Create a Windows shortcut to easily launch the RAG server. This command ensures the correct directory is set and the Python environment is used. ```batch cmd /k "cd /d D:\rag_api && C:\rag_env\Scripts\python.exe -m uvicorn main:app --host 0.0.0.0 --port 8000" ``` -------------------------------- ### Server-Sent Events (SSE) Stream Example Source: https://bothub.chat/api/documentation/ru/text_generation/responses This example illustrates the format of Server-Sent Events (SSE) received during a streaming response. Each 'data:' line contains a JSON payload representing a part of the generated content or status updates. ```text data: {"type":"response.created","response":{"id":"resp_1234567890","object":"response","status":"in_progress"}} data: {"type":"response.output_item.added","response_id":"resp_1234567890","output_index":0,"item":{"type":"message","id":"msg_abc123","role":"assistant","status":"in_progress","content":[]}} data: {"type":"response.content_part.added","response_id":"resp_1234567890","output_index":0,"content_index":0,"part":{"type":"output_text","text":""}} data: {"type":"response.content_part.delta","response_id":"resp_1234567890","output_index":0,"content_index":0,"delta":"Once"} data: {"type":"response.content_part.delta","response_id":"resp_1234567890","output_index":0,"content_index":0,"delta":" upon"} data: {"type":"response.content_part.delta","response_id":"resp_1234567890","output_index":0,"content_index":0,"delta":" a"} data: {"type":"response.content_part.delta","response_id":"resp_1234567890","output_index":0,"content_index":0,"delta":" time"} data: {"type":"response.output_item.done","response_id":"resp_1234567890","output_index":0,"item":{"type":"message","id":"msg_abc123","role":"assistant","status":"completed","content":[{"type":"output_text","text":"Once upon a time, in a world where artificial intelligence had become as common as smartphones..."}]}} data: {"type":"response.done","response":{"id":"resp_1234567890","object":"response","status":"completed","usage":{"input_tokens":12,"output_tokens":45,"total_tokens":57}}} data: [DONE] ``` -------------------------------- ### Get Available Models Source: https://bothub.chat/api/documentation/ru/replicate-api This endpoint allows you to retrieve a list of all supported Replicate models available through the API. ```APIDOC ## GET /api/v2/replicate/v1/models ### Description Retrieves a list of all supported Replicate models. ### Method GET ### Endpoint /api/v2/replicate/v1/models ### Request Headers - Content-Type: application/json - Authorization: Bearer ### Response #### Success Response (200) Returns a JSON object containing a list of available models. ### Request Example ```bash curl https://bothub.chat/api/v2/replicate/v1/models \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ' ``` ``` -------------------------------- ### Run OpenClaw Diagnostics Source: https://bothub.chat/api/documentation/ru/integration/openclaw Perform a diagnostic check on your OpenClaw installation and configurations. This command helps identify potential issues. ```bash openclaw doctor ``` -------------------------------- ### Synchronous Chat Completion in JavaScript Source: https://bothub.chat/api/documentation/ru/text_generation/chat-completions Use this for standard, non-streaming text generation. Ensure the openai library is installed and configured. ```javascript async function main() { const chatCompletion = await openai.chat.completions.create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'gpt-5-mini', }); } main(); ``` -------------------------------- ### Gemini 3 Pro Image Preview (with quality settings) Source: https://bothub.chat/api/documentation/ru/image_generation This snippet demonstrates how to generate an image using the 'gemini-3-pro-image-preview' model with specific image configurations for aspect ratio and size. It also shows how to process the response, extracting and saving the generated image from the data URL. ```APIDOC ## Gemini 3 Pro Image Preview (with quality settings) This operation allows for image generation using the `gemini-3-pro-image-preview` model. You can specify `aspect_ratio` and `image_size` within the `image_config` object, and define `response_modalities` to control the output format. ### Method POST ### Endpoint /chat/completions ### Request Body - **model** (string) - Required - The model to use, e.g., `gemini-3-pro-image-preview`. - **messages** (array) - Required - An array of message objects, where each object has a `role` and `content`. - **extra_body** (object) - Optional - Contains additional configuration for image generation. - **image_config** (object) - Optional - Configuration for the generated image. - **aspect_ratio** (string) - Optional - The desired aspect ratio of the image. Allowed values: '1:1', '16:9', '9:16', '4:3', '3:4'. - **image_size** (string) - Optional - The desired resolution of the image. Allowed values: '1K', '2K', '4K'. - **response_modalities** (array) - Optional - Specifies the types of content to return. Allowed values: 'IMAGE', 'TEXT'. ### Request Example (JavaScript) ```javascript import OpenAI from 'openai'; import fs from 'fs'; const openai = new OpenAI(); async function generateWithGemini3Pro() { const response = await openai.chat.completions.create({ model: 'gemini-3-pro-image-preview', messages: [ { role: 'user', content: 'Создай красивую бабочку на цветке' } ], extra_body: { image_config: { aspect_ratio: '16:9', image_size: '2K' }, response_modalities: ['IMAGE', 'TEXT'] } }); const message = response.choices[0].message; if (message.images && message.images.length > 0) { message.images.forEach((image, index) => { const imageUrl = image.image_url.url; const base64Data = imageUrl.split(',')[1]; const buffer = Buffer.from(base64Data, 'base64'); const filename = `gemini3_pro_generated_${index}.png`; fs.writeFileSync(filename, buffer); console.log(`Image ${index + 1} saved to ${filename}`); }); } } generateWithGemini3Pro(); ``` ### Request Example (Python) ```python from openai import OpenAI import base64 client = OpenAI() response = client.chat.completions.create( model='gemini-3-pro-image-preview', messages=[ { 'role': 'user', 'content': 'Создай красивую бабочку на цветке' } ], extra_body={ 'image_config': { 'aspect_ratio': '16:9', 'image_size': '2K' }, 'response_modalities': ['IMAGE', 'TEXT'] } ) message = response.choices[0].message if hasattr(message, 'images') and message.images: for index, image in enumerate(message.images): image_url = image.image_url.url base64_data = image_url.split(',')[1] image_data = base64.b64decode(base64_data) filename = f'gemini3_pro_generated_{index}.png' with open(filename, 'wb') as f: f.write(image_data) print(f'Image {index + 1} saved to {filename}') ``` ### Request Example (cURL) ```curl curl https://openai.bothub.chat/v1/chat/completions \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer <ваш токен доступа>' \ -d { "model": "gemini-3-pro-image-preview", "messages": [ { "role": "user", "content": "Создай красивую бабочку на цветке" } ], "image_config": { "aspect_ratio": "16:9", "image_size": "2K" }, "response_modalities": ["IMAGE", "TEXT"] } ``` ### Response Example (Success) ```json { "id": "chatcmpl-...", "object": "chat.completion", "created": 1234567890, "model": "gemini-2.5-flash-image", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "...", "inline_data": { "mime_type": "image/png", "data": "iVBORw0KGgo... (base64 encoded image)" } }, "finish_reason": "stop" } ] } ``` ``` -------------------------------- ### Translate Audio with Verbose JSON Response Source: https://bothub.chat/api/documentation/ru/translation Get timestamps and additional metadata along with the translation by specifying `response_format: verbose_json`. ```APIDOC ## POST /audio/translations (verbose_json) ### Description Translates audio into English text and provides detailed metadata including timestamps. ### Method POST ### Endpoint /audio/translations ### Parameters #### Request Body - **file** (file) - Required - The audio file to translate. - **model** (string) - Required - The model to use for translation, e.g., "whisper-1". - **response_format** (string) - Optional - Specifies the format of the response. Use "verbose_json" for detailed output. ### Request Example ```json { "file": "/path/to/audio.mp3", "model": "whisper-1", "response_format": "verbose_json" } ``` ### Response #### Success Response (200) - **text** (string) - The translated text in English. - **segments** (array) - An array of segment objects, each containing timestamp and text information. ``` ```javascript const translation = await openai.audio.translations.create({ file: fs.createReadStream("/path/to/audio.mp3"), model: "whisper-1", response_format: "verbose_json", }); console.log(translation.text); console.log(translation.segments); ``` ```python translation = client.audio.translations.create( model="whisper-1", file=audio_file, response_format="verbose_json", ) print(translation.text) print(translation.segments) ``` ```curl curl https://openai.bothub.chat/v1/audio/translations \ -H "Authorization: Bearer " \ -H "Content-Type: multipart/form-data" \ -F file="@/path/to/audio.mp3" \ -F model="whisper-1" \ -F response_format="verbose_json" ``` -------------------------------- ### Simple Text Input with Python Source: https://bothub.chat/api/documentation/ru/text_generation/responses This Python snippet demonstrates how to make a POST request to the API for simple text-based responses. Replace 'YOUR_BOTHUB_API_KEY' with your actual key. ```python import requests response = requests.post( 'https://openai.bothub.chat/v1/responses', headers={ 'Authorization': 'Bearer YOUR_BOTHUB_API_KEY', 'Content-Type': 'application/json', }, json={ 'model': 'gpt-4.1-mini', 'input': 'What is the meaning of life?', 'max_output_tokens': 9000, } ) result = response.json() print(result) ``` -------------------------------- ### API Response Format Source: https://bothub.chat/api/documentation/ru/text_generation/responses This is an example of the structured JSON response you can expect from the API. It includes details about the generated content, usage, and status. ```json { "id": "resp_1234567890", "object": "response", "created_at": 1234567890, "model": "gpt-4.1-mini", "output": [ { "type": "message", "id": "msg_abc123", "status": "completed", "role": "assistant", "content": [ { "type": "output_text", "text": "The meaning of life is a philosophical question that has been pondered for centuries...", "annotations": [] } ] } ], "usage": { "input_tokens": 12, "output_tokens": 45, "total_tokens": 57 }, "status": "completed" } ``` -------------------------------- ### Конфигурация OpenClaw с переменной окружения для ключа BotHub Source: https://bothub.chat/api/documentation/ru/integration/openclaw Используйте переменную окружения `BOTHUB_API_KEY` для безопасного хранения вашего API-ключа BotHub в `openclaw.json`. Задайте переменную окружения в `.env` или экспортируйте напрямую. ```json { "models": { "mode": "merge", "providers": { "bothub": { "baseUrl": "https://bothub.ru/v1", "apiKey": "${BOTHUB_API_KEY}", "api": "openai-completions", "models": [ { "id": "claude-sonnet-4-6", "name": "Claude Sonnet 4.6 (BotHub)", "contextWindow": 200000, "maxTokens": 8192, "reasoning": false, "input": ["text", "image"] } ] } } }, "agents": { "defaults": { "model": { "primary": "bothub/claude-sonnet-4-6" } } } } ``` ```bash # В .env или ~/.openclaw/.env BOTHUB_API_KEY=ВАШ_КЛЮЧ_BOTHUB # Или экспортируйте напрямую export BOTHUB_API_KEY=ВАШ_КЛЮЧ_BOTHUB ``` -------------------------------- ### Apply OpenClaw Gateway Configuration Source: https://bothub.chat/api/documentation/ru/integration/openclaw Apply a new configuration to the OpenClaw gateway from a specified JSON file. Ensure the configuration file is correctly formatted. ```bash openclaw gateway config.apply --file ~/.openclaw/openclaw.json ``` -------------------------------- ### GPT-5 Image Generation Source: https://bothub.chat/api/documentation/ru/image_generation This section demonstrates how to generate images using the GPT-5 model via the API. It includes examples for Python and cURL. ```APIDOC ## GPT-5 Image Generation ### Description Generates an image based on a user's text prompt using the GPT-5 model. ### Method POST ### Endpoint /v1/chat/completions ### Request Body - **model** (string) - Required - The model to use, e.g., 'gpt-5-image' or 'gpt-5-image-mini'. - **messages** (array) - Required - An array of message objects. - **role** (string) - Required - The role of the message sender ('user'). - **content** (string) - Required - The text prompt for image generation. ### Request Example (Python) ```python from openai import OpenAI client = OpenAI() response = client.chat.completions.create( model='gpt-5-image', # or 'gpt-5-image-mini' messages=[ { 'role': 'user', 'content': 'Сгенерируй изображение киберпанк города на закате' } ] ) # Extracting images from the response message = response.choices[0].message if hasattr(message, 'images') and message.images: # Images are returned in data URL format for index, image in enumerate(message.images): image_url = image.image_url.url base64_data = image_url.split(',')[1] # Extract base64 from data URL image_data = base64.b64decode(base64_data) filename = f'gpt5_generated_{index}.png' with open(filename, 'wb') as f: f.write(image_data) print(f'Image {index + 1} saved to {filename}') ``` ### Request Example (cURL) ```bash curl https://openai.bothub.chat/v1/chat/completions \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ' \ -d { "model": "gpt-5-image", "messages": [ { "role": "user", "content": "Сгенерируй изображение киберпанк города на закате" } ] } ``` ### Response Images are returned in the response, typically as data URLs, which can be decoded to obtain image files. ``` -------------------------------- ### Full OpenClaw Configuration with BotHub Models Source: https://bothub.chat/api/documentation/ru/integration/openclaw This JSON configuration sets up default agents with primary and fallback models from BotHub. It also details the BotHub provider, including its base URL, API key, API type, and a list of models with their specific configurations like context window, token limits, input types, and costs. ```json { "agents": { "defaults": { "model": { "primary": "bothub/claude-sonnet-4-6", "fallbacks": ["bothub/gpt-5.2", "bothub/deepseek-chat"] }, "models": { "bothub/claude-sonnet-4-6": { "alias": "Claude" }, "bothub/gpt-5.2": { "alias": "GPT-5.2" }, "bothub/gpt-5.4": { "alias": "GPT-5.4" }, "bothub/deepseek-chat": { "alias": "DeepSeek" } } } }, "models": { "mode": "merge", "providers": { "bothub": { "baseUrl": "https://bothub.ru/v1", "apiKey": "${BOTHUB_API_KEY}", "api": "openai-completions", "models": [ { "id": "claude-sonnet-4-6", "name": "Claude Sonnet 4.6", "contextWindow": 200000, "maxTokens": 8192, "reasoning": false, "input": ["text", "image"], "cost": { "input": 3.0, "output": 15.0, "cacheRead": 0, "cacheWrite": 0 } }, { "id": "gpt-5.2", "name": "GPT-5.2", "contextWindow": 400000, "maxTokens": 128000, "reasoning": false, "input": ["text", "image"], "cost": { "input": 1.97, "output": 15.75, "cacheRead": 0, "cacheWrite": 0 } }, { "id": "gpt-5.4", "name": "GPT-5.4", "contextWindow": 1050000, "maxTokens": 128000, "reasoning": false, "input": ["text", "image"], "cost": { "input": 2.81, "output": 16.88, "cacheRead": 0, "cacheWrite": 0 } }, { "id": "deepseek-chat", "name": "DeepSeek Chat", "contextWindow": 128000, "maxTokens": 8192, "reasoning": false, "input": ["text"], "cost": { "input": 0.14, "output": 0.28, "cacheRead": 0, "cacheWrite": 0 } } ] } } } } ```