### Get Image to Video Models (cURL, Java, JavaScript, PHP, Python) Source: https://docs.akool.com/ai-tools-suite/aimodel This snippet demonstrates how to fetch a list of available image-to-video models from the Akool API. It includes examples for making the GET request using cURL, Java, JavaScript, PHP, and Python. The API requires an 'x-api-key' header for authentication. The response contains metadata about each model, including its type, description, supported resolutions, and pricing information. ```cURL curl --location 'https://openapi.akool.com/api/open/v4/aigModel/list?types[]=1501' \ --header 'x-api-key: {{API Key}}' ``` ```Java OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("https://openapi.akool.com/api/open/v4/aigModel/list?types[]=1501") .method("GET", null) .addHeader("x-api-key", "{{API Key}}") .build(); Response response = client.newCall(request).execute(); ``` ```JavaScript const myHeaders = new Headers(); myHeaders.append("x-api-key", "{{API Key}}"); const requestOptions = { method: "GET", headers: myHeaders, redirect: "follow" }; fetch("https://openapi.akool.com/api/open/v4/aigModel/list?types[]=1501", requestOptions) .then((response) => response.text()) .then((result) => console.log(result)) .catch((error) => console.error(error)); ``` ```PHP '{{API Key}}' ]; $request = new Request('GET', 'https://openapi.akool.com/api/open/v4/aigModel/list?types[]=1501', $headers); $res = $client->sendAsync($request)->wait(); echo $res->getBody(); ?> ``` ```Python import requests url = "https://openapi.akool.com/api/open/v4/aigModel/list?types[]=1501" headers = { 'x-api-key':'{{API Key}}' } response = requests.request("GET", url, headers=headers) print(response.text) ``` -------------------------------- ### Install Streaming Avatar SDKs Source: https://docs.akool.com/implementation-guide/streaming-avatar Commands to install the necessary SDK packages for Agora, LiveKit, or TRTC via npm or yarn. ```bash npm install agora-rtc-sdk-ng # or yarn add agora-rtc-sdk-ng ``` ```bash npm install livekit-client # or yarn add livekit-client ``` ```bash npm install trtc-sdk-v5 # or yarn add trtc-sdk-v5 ``` -------------------------------- ### Publish and Control Audio Stream (TRTC) Source: https://docs.akool.com/implementation-guide/streaming-avatar This example shows how to manage local audio streams with the TRTC SDK. It includes functions to start and stop audio capture, as well as mute and unmute the local audio. The `setupAudioInteraction` function provides methods to control the audio state, ensuring proper handling of audio publishing and unpublishing. ```typescript async function publishAudio(client: TRTC) { try { // Start local audio capture await client.startLocalAudio({ quality: TRTC.TRTCAudioQualityDefault }); console.log("Audio publishing successful"); return true; } catch (error) { console.error("Error publishing audio:", error); throw error; } } // Example usage with audio controls async function setupAudioInteraction(client: TRTC) { let isAudioEnabled = false; // Start audio async function startAudio() { try { await publishAudio(client); isAudioEnabled = true; } catch (error) { console.error("Failed to start audio:", error); } } // Stop audio async function stopAudio() { if (isAudioEnabled) { try { await client.stopLocalAudio(); isAudioEnabled = false; } catch (error) { console.error("Failed to stop audio:", error); } } } // Mute/unmute audio function toggleAudio(muted: boolean) { if (isAudioEnabled) { client.muteLocalAudio(muted); } } return { startAudio, stopAudio, toggleAudio }; } ``` -------------------------------- ### Initialize Avatar with Audio Controls (Agora) Source: https://docs.akool.com/implementation-guide/streaming-avatar This snippet demonstrates the complete integration of audio functionality when initializing a streaming avatar with the Agora SDK. It shows how to initialize the avatar, set up audio controls, start audio, toggle mute states, and finally stop the audio stream, providing a clear example of the audio interaction lifecycle. ```typescript async function initializeWithAudio() { try { // Initialize avatar const client = await initializeStreamingAvatar(); // Setup audio controls const audioControls = await setupAudioInteraction(client); // Start audio when needed await audioControls.startAudio(); // Example of muting/unmuting audioControls.toggleAudio(true); // mute audioControls.toggleAudio(false); // unmute // Stop audio when done await audioControls.stopAudio(); } catch (error) { console.error("Error initializing with audio:", error); } } ``` -------------------------------- ### Delete Knowledge Base Request Examples Source: https://docs.akool.com/ai-tools-suite/knowledge-base Provides examples of how to make a DELETE request to the Akool API to delete a knowledge base, shown in cURL, Java, Javascript, PHP, and Python. These examples illustrate how to set headers, content type, and the request body. ```bash curl --location --request DELETE 'https://openapi.akool.com/api/open/v4/knowledge/delete' \ --header 'x-api-key: {{API Key}}' \ --header 'Content-Type: application/json' \ --data '{ "id": "64f8a1b2c3d4e5f6a7b8c9d0" }' ``` ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); MediaType mediaType = MediaType.parse("application/json"); RequestBody body = RequestBody.create(mediaType, "{\n \"id\": \"64f8a1b2c3d4e5f6a7b8c9d0\"\n}"); Request request = new Request.Builder() .url("https://openapi.akool.com/api/open/v4/knowledge/delete") .method("DELETE", body) .addHeader("x-api-key", "{{API Key}}") .addHeader("Content-Type", "application/json") .build(); Response response = client.newCall(request).execute(); ``` ```javascript const myHeaders = new Headers(); myHeaders.append("x-api-key", "{{API Key}}"); myHeaders.append("Content-Type", "application/json"); const raw = JSON.stringify({ "id": "64f8a1b2c3d4e5f6a7b8c9d0" }); const requestOptions = { method: "DELETE", headers: myHeaders, body: raw, redirect: "follow" }; fetch("https://openapi.akool.com/api/open/v4/knowledge/delete", requestOptions) .then((response) => response.text()) .then((result) => console.log(result)) .catch((error) => console.error(error)); ``` ```php '{{API Key}}', 'Content-Type' => 'application/json' ]; $body = '{ "id": "64f8a1b2c3d4e5f6a7b8c9d0" }'; $request = new Request('DELETE', 'https://openapi.akool.com/api/open/v4/knowledge/delete', $headers, $body); $res = $client->sendAsync($request)->wait(); echo $res->getBody(); ?> ``` ```python import requests import json url = "https://openapi.akool.com/api/open/v4/knowledge/delete" payload = json.dumps({ "id": "64f8a1b2c3d4e5f6a7b8c9d0" }) headers = { 'x-api-key':'{{API Key}}', 'Content-Type': 'application/json' } response = requests.request("DELETE", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### Initialize Akool Streaming Avatar SDK in Browser Source: https://docs.akool.com/sdk/jssdk-start Demonstrates how to include the SDK via CDN, initialize the GenericAgoraSDK, and handle remote video stream subscriptions. It also shows the process for joining a channel and starting a chat session. ```html ``` -------------------------------- ### Get Video Info by Model ID - JavaScript Source: https://docs.akool.com/ai-tools-suite/lip-sync This JavaScript example demonstrates fetching video information by video_model_id using the Fetch API. It includes setting the necessary headers with an API key for authentication. ```javascript const myHeaders = new Headers(); myHeaders.append("x-api-key", "{{API Key}}"); const requestOptions = { method: "GET", headers: myHeaders, redirect: "follow", }; fetch( "http://openapi.akool.com/api/open/v3/content/video/infobymodelid?video_model_id=66160f989dfc997ac289037b", requestOptions ) .then((response) => response.text()) .then((result) => console.log(result)) .catch((error) => console.error(error)); ``` -------------------------------- ### Initialize and Use Akool Streaming Avatar SDK Source: https://docs.akool.com/sdk/jssdk-start Demonstrates how to instantiate the SDK, register event handlers, join an Agora channel, and send messages to the avatar. ```javascript import { GenericAgoraSDK } from 'akool-streaming-avatar-sdk'; const agoraSDK = new GenericAgoraSDK({ mode: "rtc", codec: "vp8" }); agoraSDK.on({ onStreamMessage: (uid, message) => console.log("Received:", uid, message), onUserPublished: async (user, mediaType) => { const remoteTrack = await agoraSDK.getClient().subscribe(user, mediaType); remoteTrack?.play(mediaType === 'video' ? 'remote-video' : undefined); } }); const akoolSession = await fetch('your-backend-url'); const { data: { credentials } } = await akoolSession.json(); await agoraSDK.joinChannel({ agora_app_id: credentials.agora_app_id, agora_channel: credentials.agora_channel, agora_token: credentials.agora_token, agora_uid: credentials.agora_uid }); await agoraSDK.joinChat({ vid: "voice-id", lang: "en", mode: 2 }); await agoraSDK.sendMessage("Hello, world!"); ``` -------------------------------- ### Publish and Control Audio Stream (LiveKit) Source: https://docs.akool.com/implementation-guide/streaming-avatar This code illustrates how to create and publish a local audio track using the LiveKit client SDK. It provides functions to initiate audio, terminate it, and toggle mute status. The `setupAudioInteraction` function returns an object with methods to control the audio stream within a LiveKit room. ```typescript import { createLocalAudioTrack } from 'livekit-client'; async function publishAudio(room: Room) { // Create a microphone audio track const audioTrack = await createLocalAudioTrack(); try { // Publish the audio track to the room await room.localParticipant.publishTrack(audioTrack); console.log("Audio publishing successful"); return audioTrack; } catch (error) { console.error("Error publishing audio:", error); throw error; } } // Example usage with audio controls async function setupAudioInteraction(room: Room) { let audioTrack; // Start audio async function startAudio() { try { audioTrack = await publishAudio(room); } catch (error) { console.error("Failed to start audio:", error); } } // Stop audio async function stopAudio() { if (audioTrack) { // Stop and unpublish the audio track audioTrack.stop(); await room.localParticipant.unpublishTrack(audioTrack); audioTrack = null; } } // Mute/unmute audio function toggleAudio(muted: boolean) { if (audioTrack) { audioTrack.setMuted(muted); } } return { startAudio, stopAudio, toggleAudio }; } ``` -------------------------------- ### Get Avatar Detail API Request Examples Source: https://docs.akool.com/ai-tools-suite/talking-avatar Demonstrates how to fetch detailed information about an avatar using the Akool API. This endpoint requires an avatar ID and supports authorization via x-api-key or Authorization header. The response includes avatar status, URL, and other metadata. ```bash curl --location 'https://openapi.akool.com/api/open/v3/avatar/detail?id=66a1a02d591ad336275eda62' \ --header 'x-api-key: {{API Key}}' ``` ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); MediaType mediaType = MediaType.parse("text/plain"); RequestBody body = RequestBody.create(mediaType, ""); Request request = new Request.Builder() .url("https://openapi.akool.com/api/open/v3/avatar/detail?id=66a1a02d591ad336275eda62") .method("GET", body) .addHeader("x-api-key", "{{API Key}}") .build(); Response response = client.newCall(request).execute(); ``` ```javascript const myHeaders = new Headers(); myHeaders.append("x-api-key", "{{API Key}}"); const requestOptions = { method: "GET", headers: myHeaders, redirect: "follow", }; fetch( "https://openapi.akool.com/api/open/v3/avatar/detail?id=66a1a02d591ad336275eda62, requestOptions ) .then((response) => response.text()) .then((result) => console.log(result)) .catch((error) => console.error(error)); ``` ```php '{{API Key}}' ]; $request = new Request('GET', 'https://openapi.akool.com/api/open/v3/avatar/detail?66a1a02d591ad336275eda62', $headers); $res = $client->sendAsync($request)->wait(); echo $res->getBody(); ``` ```python import requests url = "https://openapi.akool.com/api/open/v3/avatar/detail?id=66a1a02d591ad336275eda62" payload = {} headers = { 'x-api-key': '{{API Key}}' } response = requests.request("GET", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### SDK Initialization and Session Management Source: https://docs.akool.com/sdk/jssdk-api Methods for initializing the SDK, joining channels, and managing the streaming avatar session lifecycle. ```APIDOC ## SDK Initialization and Session Management ### Description This section covers the initialization of the GenericAgoraSDK, joining a communication channel, and starting the avatar chat session. ### Method POST /joinChannel, POST /joinChat ### Parameters #### Request Body (joinChannel) - **agora_app_id** (string) - Required - The Agora App ID. - **agora_channel** (string) - Required - The channel name. - **agora_token** (string) - Required - The temporary token for authentication. - **agora_uid** (number) - Required - Unique user ID. #### Request Body (joinChat) - **vid** (string) - Required - The voice ID for the avatar. - **lang** (string) - Required - Language code (e.g., 'en'). - **mode** (number) - Required - Interaction mode. ### Request Example { "agora_app_id": "your_app_id", "agora_channel": "channel_name", "agora_token": "token_string", "agora_uid": 12345 } ### Response #### Success Response (200) - **status** (string) - Success message indicating session initialization. ``` -------------------------------- ### POST /api/open/v4/knowledge/create Source: https://docs.akool.com/ai-tools-suite/knowledge-base Creates a new knowledge base with the provided name, prologue, prompt, documents, and URLs. ```APIDOC ## POST /api/open/v4/knowledge/create ### Description Creates a new knowledge base with the provided name, prologue, prompt, documents, and URLs. ### Method POST ### Endpoint /api/open/v4/knowledge/create ### Parameters #### Request Body - **name** (string) - Required - The name of the knowledge base. - **prologue** (string) - Required - The introductory message for the AI assistant. - **prompt** (string) - Required - The prompt to guide the AI assistant's responses. - **docs** (array of objects) - Optional - A list of documents to include in the knowledge base. - **name** (string) - Required - The name of the document. - **url** (string) - Required - The URL of the document. - **size** (integer) - Required - The size of the document in bytes. - **urls** (array of strings) - Optional - A list of URLs to include in the knowledge base. ### Request Example ```json { "name": "Customer Support KB", "prologue": "Hello, I am your AI assistant. How can I help you?", "prompt": "You are a professional AI assistant. Please answer questions based on the provided documents.", "docs": [ { "name": "user_manual.pdf", "url": "https://example.com/user_manual.pdf", "size": 1024000 } ], "urls": [ "https://example.com/help", "https://example.com/faq" ] } ``` ### Response #### Success Response (200) - **code** (integer) - The status code of the response. - **msg** (string) - The message describing the response. - **data** (object) - The data returned by the API. - **_id** (string) - The unique identifier of the knowledge base. - **team_id** (string) - The ID of the team associated with the knowledge base. - **uid** (integer) - The user ID. - **user_type** (integer) - The type of user. - **from** (integer) - The source of the knowledge base creation. - **name** (string) - The name of the knowledge base. - **prologue** (string) - The introductory message for the AI assistant. - **prompt** (string) - The prompt to guide the AI assistant's responses. - **docs** (array of objects) - A list of documents included in the knowledge base. - **urls** (array of strings) - A list of URLs included in the knowledge base. - **create_time** (integer) - The timestamp when the knowledge base was created. - **update_time** (integer) - The timestamp when the knowledge base was last updated. #### Response Example ```json { "code": 1000, "msg": "OK", "data": { "_id": "64f8a1b2c3d4e5f6a7b8c9d0", "team_id": "team_123456", "uid": 789, "user_type": 2, "from": 2, "name": "Customer Support KB", "prologue": "Hello, I am your AI assistant. How can I help you?", "prompt": "You are a professional AI assistant. Please answer questions based on the provided documents.", "docs": [ { "name": "user_manual.pdf", "url": "https://example.com/user_manual.pdf", "size": 1024000 } ], "urls": [ "https://example.com/help", "https://example.com/faq" ], "create_time": 1640995200000, "update_time": 1640995200000 } } ``` ``` -------------------------------- ### List Voices API Request (Multiple Languages) Source: https://docs.akool.com/ai-tools-suite/voiceLab This snippet demonstrates how to make a GET request to the Akool API's /api/open/v4/voice/list endpoint to retrieve a list of voices. It includes examples for cURL, Java, JavaScript, PHP, and Python, showing how to set parameters such as type, page, size, style, gender, and name, as well as the required API key. ```Bash curl --location 'https://openapi.akool.com/api/open/v4/voice/list?type=1&page=1&size=10&style=Calm,Authoritative&gender=Male&name=MyVoice' \ --header 'x-api-key: {{API Key}}' ``` ```Java OkHttpClient client = new OkHttpClient().newBuilder() .build(); MediaType mediaType = MediaType.parse("text/plain"); RequestBody body = RequestBody.create(mediaType, ""); Request request = new Request.Builder() .url("https://openapi.akool.com/api/open/v4/voice/list?type=1&page=1&size=10&style=Calm,Authoritative&gender=Male&name=MyVoice") .method("GET", body) .addHeader("x-api-key", "{{API Key}}") .build(); Response response = client.newCall(request).execute(); ``` ```Javascript const myHeaders = new Headers(); myHeaders.append("x-api-key", "{{API Key}}"); const requestOptions = { method: "GET", headers: myHeaders, redirect: "follow" }; fetch("https://openapi.akool.com/api/open/v4/voice/list?type=1&page=1&size=10&style=Calm,Authoritative&gender=Male&name=MyVoice", requestOptions) .then((response) => response.text()) .then((result) => console.log(result)) .catch((error) => console.error(error)); ``` ```PHP '{{API Key}}' ]; $request = new Request('GET', 'https://openapi.akool.com/api/open/v4/voice/list?type=1&page=1&size=10&style=Calm,Authoritative&gender=Male&name=MyVoice', $headers); $res = $client->sendAsync($request)->wait(); echo $res->getBody(); ?> ``` ```Python import requests url = "https://openapi.akool.com/api/open/v4/voice/list" payload = {} headers = { 'x-api-key':'{{API Key}}' } params = { 'type': '1', 'page': '1', 'size': '10', 'style': 'Calm,Authoritative', 'gender': 'Male', 'name': 'MyVoice' } response = requests.request("GET", url, headers=headers, data=payload, params=params) print(response.text) ``` -------------------------------- ### Get Language List Source: https://docs.akool.com/ai-tools-suite/video-translation Get a list of supported languages for video translation. ```APIDOC ## GET /ai-tools-suite/video-translation/get-languages ### Description Fetches a list of all languages supported by the video translation service. ### Method GET ### Endpoint /ai-tools-suite/video-translation/get-languages ### Response #### Success Response (200) - **languages** (array) - A list of supported language objects. - **code** (string) - The language code (e.g., "en", "es"). - **name** (string) - The name of the language (e.g., "English", "Spanish"). - **voice_ids** (array) - A list of available voice IDs for this language. #### Response Example ```json { "languages": [ { "code": "en", "name": "English", "voice_ids": ["voice-en-1", "voice-en-2"] }, { "code": "es", "name": "Spanish", "voice_ids": ["voice-es-1"] } ] } ``` ``` -------------------------------- ### Create Knowledge Base with Akool API (JavaScript) Source: https://docs.akool.com/ai-tools-suite/knowledge-base Demonstrates how to create a knowledge base using the Akool API with a JavaScript fetch request. It includes setting headers, constructing a JSON payload with knowledge base details, and handling the response. ```javascript myHeaders.append("Content-Type", "application/json"); const raw = JSON.stringify({ "name": "Customer Support KB", "prologue": "Hello, I am your AI assistant. How can I help you?", "prompt": "You are a professional AI assistant. Please answer questions based on the provided documents.", "docs": [ { "name": "user_manual.pdf", "url": "https://example.com/user_manual.pdf", "size": 1024000 } ], "urls": [ "https://example.com/help", "https://example.com/faq" ] }); const requestOptions = { method: "POST", headers: myHeaders, body: raw, redirect: "follow" }; fetch("https://openapi.akool.com/api/open/v4/knowledge/create", requestOptions) .then((response) => response.text()) .then((result) => console.log(result)) .catch((error) => console.error(error)); ``` -------------------------------- ### Create Knowledge Base with Akool API (Python) Source: https://docs.akool.com/ai-tools-suite/knowledge-base Shows how to create a knowledge base using the Akool API in Python. This example uses the `requests` library to send a POST request with an API key, content type, and a JSON payload. ```python import requests import json url = "https://openapi.akool.com/api/open/v4/knowledge/create" payload = json.dumps({ "name": "Customer Support KB", "prologue": "Hello, I am your AI assistant. How can I help you?", "prompt": "You are a professional AI assistant. Please answer questions based on the provided documents.", "docs": [ { "name": "user_manual.pdf", "url": "https://example.com/user_manual.pdf", "size": 1024000 } ], "urls": [ "https://example.com/help", "https://example.com/faq" ] }) headers = { 'x-api-key':'{{API Key}}', 'Content-Type': 'application/json' } response = requests.request("POST", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### Get User Credit Info API Source: https://docs.akool.com/ai-tools-suite/faceswap Get faceswap user credit information. ```APIDOC ## GET /ai-tools-suite/faceswap/get-credit ### Description Retrieves the current credit balance and usage information for the authenticated user. ### Method GET ### Endpoint /ai-tools-suite/faceswap/get-credit ### Parameters (No parameters required, uses authentication token) ### Request Example ``` GET /ai-tools-suite/faceswap/get-credit ``` ### Response #### Success Response (200) - **code** (integer) - Response code (1000 for success). - **message** (string) - Success message. - **credits** (object) - Object containing credit information: - **balance** (integer) - Remaining credits. - **used** (integer) - Credits used. - **total** (integer) - Total credits allocated. #### Response Example ```json { "code": 1000, "message": "Success", "credits": { "balance": 500, "used": 150, "total": 650 } } ``` ``` -------------------------------- ### Retrieve Knowledge Base Details (HTTP, cURL, Java, JavaScript, PHP, Python) Source: https://docs.akool.com/ai-tools-suite/knowledge-base This snippet demonstrates how to fetch detailed information about a specific knowledge base using its ID. It includes examples for making the GET request via HTTP, cURL, Java, JavaScript, PHP, and Python. Authentication is handled using an 'x-api-key' header. The API returns a JSON object containing the knowledge base details or an error code. ```HTTP GET https://openapi.akool.com/api/open/v4/knowledge/detail?id=64f8a1b2c3d4e5f6a7b8c9d0 ``` ```cURL curl --location 'https://openapi.akool.com/api/open/v4/knowledge/detail?id=64f8a1b2c3d4e5f6a7b8c9d0' \ --header 'x-api-key: {{API Key}}' ``` ```Java OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("https://openapi.akool.com/api/open/v4/knowledge/detail?id=64f8a1b2c3d4e5f6a7b8c9d0") .method("GET", null) .addHeader("x-api-key", "{{API Key}}") .build(); Response response = client.newCall(request).execute(); ``` ```JavaScript const myHeaders = new Headers(); myHeaders.append("x-api-key", "{{API Key}}"); const requestOptions = { method: "GET", headers: myHeaders, redirect: "follow" }; fetch("https://openapi.akool.com/api/open/v4/knowledge/detail?id=64f8a1b2c3d4e5f6a7b8c9d0", requestOptions) .then((response) => response.text()) .then((result) => console.log(result)) .catch((error) => console.error(error)); ``` ```PHP '{{API Key}}' ]; $request = new Request('GET', 'https://openapi.akool.com/api/open/v4/knowledge/detail?id=64f8a1b2c3d4e5f6a7b8c9d0', $headers); $res = $client->sendAsync($request)->wait(); echo $res->getBody(); ``` ```Python import requests url = "https://openapi.akool.com/api/open/v4/knowledge/detail?id=64f8a1b2c3d4e5f6a7b8c9d0" headers = { 'x-api-key':'{{API Key}}' } response = requests.request("GET", url, headers=headers) print(response.text) ``` -------------------------------- ### Create Knowledge Base API Implementation Source: https://docs.akool.com/ai-tools-suite/knowledge-base Demonstrates how to create a new knowledge base using the Akool API. The endpoint accepts a JSON body containing configuration details and requires an API key for authentication. ```bash curl --location 'https://openapi.akool.com/api/open/v4/knowledge/create' \ --header 'x-api-key: {{API Key}}' \ --header 'Content-Type: application/json' \ --data '{ "name": "Customer Support KB", "prologue": "Hello, I am your AI assistant. How can I help you?", "prompt": "You are a professional AI assistant. Please answer questions based on the provided documents.", "docs": [ { "name": "user_manual.pdf", "url": "https://example.com/user_manual.pdf", "size": 1024000 } ], "urls": [ "https://example.com/help", "https://example.com/faq" ] }' ``` ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); MediaType mediaType = MediaType.parse("application/json"); RequestBody body = RequestBody.create(mediaType, "{\n \"name\": \"Customer Support KB\",\n \"prologue\": \"Hello, I am your AI assistant. How can I help you?\",\n \"prompt\": \"You are a professional AI assistant. Please answer questions based on the provided documents.\",\n \"docs\": [\n {\n \"name\": \"user_manual.pdf\",\n \"url\": \"https://example.com/user_manual.pdf\",\n \"size\": 1024000\n }\n ],\n \"urls\": [\n \"https://example.com/help\",\n \"https://example.com/faq\"\n ]\n}"); Request request = new Request.Builder() .url("https://openapi.akool.com/api/open/v4/knowledge/create") .method("POST", body) .addHeader("x-api-key", "{{API Key}}") .addHeader("Content-Type", "application/json") .build(); Response response = client.newCall(request).execute(); ``` ```javascript const myHeaders = new Headers(); myHeaders.append("x-api-key", "{{API Key}}"); ``` -------------------------------- ### Create Knowledge Base and Use in Avatar Session (Bash) Source: https://docs.akool.com/ai-tools-suite/knowledge-base This bash script demonstrates a complete workflow for integrating a knowledge base with a Streaming Avatar. It includes two `curl` commands: the first creates a new knowledge base with specified documents and URLs, and the second uses the obtained knowledge ID to create a streaming avatar session. ```bash # 1. Create a knowledge base curl -X POST "https://openapi.akool.com/api/open/v4/knowledge/create" \ -H "x-api-key: {{API Key}}" \ -H "Content-Type: application/json" \ -d '{ "name": "Customer Support KB", "prologue": "Hello, I am your customer support assistant. How can I help you today?", "prompt": "You are a helpful customer support assistant. Use the provided documents to answer questions accurately.", "docs": [ { "name": "user_guide.pdf", "url": "https://example.com/user_guide.pdf", "size": 1024000 } ], "urls": [ "https://example.com/help", "https://example.com/faq" ] }' # 2. Use the knowledge base in a streaming avatar session curl -X POST "https://openapi.akool.com/api/open/v4/liveAvatar/session/create" \ -H "x-api-key: {{API Key}}" \ -H "Content-Type: application/json" \ -d '{ "avatar_id": "your_avatar_id", "knowledge_id": "KNOWLEDGE_ID_FROM_STEP_1" }' ``` -------------------------------- ### Get Video Info by Model ID - PHP Source: https://docs.akool.com/ai-tools-suite/lip-sync This PHP snippet illustrates how to retrieve video information using the video_model_id. It makes a GET request with the required x-api-key header. ```php '{{API Key}}' ]; $request = new Request('GET', 'http://openapi.akool.com/api/open/v3/content/video/infobymodelid?video_model_id=66160f989dfc997ac289037b', $headers); $res = $client->sendAsync($request)->wait(); echo $res->getBody(); ``` -------------------------------- ### Initialize and Manage Akool Streaming Avatar SDK Source: https://docs.akool.com/sdk/jssdk-api Demonstrates the full lifecycle of the Akool SDK including initialization, event listener setup, channel joining, and media control functions. It requires valid Agora credentials and handles asynchronous operations for session management. ```javascript import { GenericAgoraSDK } from 'akool-streaming-avatar-sdk'; const agoraSDK = new GenericAgoraSDK({ mode: "rtc", codec: "vp8" }); agoraSDK.on({ onStreamMessage: (uid, message) => console.log("Received message from", uid, ":", message), onException: (error) => console.error("An exception occurred:", error), onMessageReceived: (message) => updateMessageDisplay(message), onMessageUpdated: (message) => updateExistingMessage(message), onNetworkStatsUpdated: (stats) => updateNetworkQuality(stats), onTokenWillExpire: () => refreshToken(), onTokenDidExpire: () => handleTokenExpiry(), onUserPublished: async (user, mediaType) => { const remoteTrack = await agoraSDK.getClient().subscribe(user, mediaType); remoteTrack?.play(mediaType === 'video' ? 'remote-video-container' : undefined); } }); async function initializeSession() { const response = await fetch('/api/get-agora-credentials'); const credentials = await response.json(); await agoraSDK.joinChannel({ agora_app_id: credentials.agora_app_id, agora_channel: credentials.agora_channel, agora_token: credentials.agora_token, agora_uid: credentials.agora_uid }); await agoraSDK.joinChat({ vid: "your-voice-id", lang: "en", mode: 2 }); } async function sendMessage(content) { await agoraSDK.sendMessage(content); } async function toggleMicrophone() { await agoraSDK.toggleMic(); } async function cleanup() { await agoraSDK.closeStreaming(); } ``` -------------------------------- ### Install Akool Streaming Avatar SDK Source: https://docs.akool.com/sdk/jssdk-start Methods for adding the SDK to your project via NPM or CDN. ```bash npm install akool-streaming-avatar-sdk ``` ```html ``` -------------------------------- ### Get Video Info by Model ID - Python Source: https://docs.akool.com/ai-tools-suite/lip-sync This Python code uses the requests library to fetch video details by video_model_id. It sends a GET request with the API key in the headers. ```python import requests url = "http://openapi.akool.com/api/open/v3/content/video/infobymodelid?video_model_id=66160f989dfc997ac289037b" payload = {} headers = { 'x-api-key':'{{API Key}}' } response = requests.request("GET", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### Get Streaming Avatar Detail OpenAPI Definition Source: https://docs.akool.com/ai-tools-suite/live-avatar/detail The OpenAPI specification for the GET request to retrieve streaming avatar details. It defines the endpoint, required avatar_id parameter, and the schema for the successful response. ```yaml paths: /api/open/v4/liveAvatar/avatar/detail: get: tags: - Avatar Management summary: Get Streaming Avatar Detail parameters: - name: avatar_id in: query required: true schema: type: string responses: '200': description: Avatar details content: application/json: schema: $ref: '#/components/schemas/AvatarDetail' ``` -------------------------------- ### Initialize Client/Room Source: https://docs.akool.com/implementation-guide/streaming-avatar Initializes the client or room for different providers (Agora, LiveKit, TRTC) with provided credentials. ```APIDOC ## Initialize Client/Room ### Description Initializes the client or room for different providers (Agora, LiveKit, TRTC) with provided credentials. ### Method Asynchronous function ### Endpoint N/A (Client-side initialization) ### Parameters - **credentials** (object) - Required - Object containing provider-specific credentials. - **agora_app_id** (string) - Required for Agora - **agora_channel** (string) - Required for Agora - **agora_token** (string) - Required for Agora - **agora_uid** (string) - Required for Agora - **livekit_url** (string) - Required for LiveKit - **livekit_token** (string) - Required for LiveKit - **trtc_app_id** (string) - Required for TRTC - **trtc_room_id** (string) - Required for TRTC - **trtc_user_id** (string) - Required for TRTC - **trtc_user_sig** (string) - Required for TRTC ### Request Example ```json { "agora_app_id": "YOUR_AGORA_APP_ID", "agora_channel": "YOUR_AGORA_CHANNEL", "agora_token": "YOUR_AGORA_TOKEN", "agora_uid": "YOUR_AGORA_UID" } ``` ### Response - **client** (object) - The initialized client object (AgoraRTC.Client or TRTC). - **room** (object) - The initialized room object (LiveKit Room). ### Response Example ```json // Returns an initialized client or room object based on the provider ``` ``` -------------------------------- ### Get Video Info by Model ID - Java Source: https://docs.akool.com/ai-tools-suite/lip-sync This Java code snippet shows how to make a GET request to retrieve video information using the video_model_id. It utilizes the OkHttpClient library and requires an API key. ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); MediaType mediaType = MediaType.parse("text/plain"); RequestBody body = RequestBody.create(mediaType, ""); Request request = new Request.Builder() .url("http://openapi.akool.com/api/open/v3/content/video/infobymodelid?video_model_id=66160f989dfc997ac289037b") .method("GET", body) .addHeader("x-api-key", "{{API Key}}") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Best Practices Source: https://docs.akool.com/ai-tools-suite/face-detection/detect-faces General recommendations for using the Akool API effectively. ```APIDOC ## Best Practices * **URL Requirements**: Use HTTPS, ensure publicly accessible. * **Video num_frames**: Short videos (5-10), Medium (10-20), Long (20-50). * **Performance**: Use `single_face=true` when only one face is needed. ``` -------------------------------- ### Get Available Effects - Python Source: https://docs.akool.com/ai-tools-suite/image2video This Python snippet shows how to fetch available video effects using the requests library. It performs a GET request to the Akool API endpoint, providing the 'x-api-key' in the request headers for authentication. The response text is then printed. ```python import requests url = "https://openapi.akool.com/api/open/v4/image2Video/effects" headers = { 'x-api-key':'{{API Key}}' } response = requests.request("GET", url, headers=headers) print(response.text) ``` -------------------------------- ### Setup HTML Structure for Avatar Source: https://docs.akool.com/sdk/jssdk-start Basic HTML boilerplate required to render the video stream and interact with the avatar. ```html