The id of the conversation that you want the clone generated response to be
a part of Clone responses use the history of the selectd conversation while
generating a response, so ensure that this id is correct Use the Get
Conversation History endpoint if you
would like to see the previous messages in a given conversation in order to
validate
Your audio sent as a single blob of base64 encoded bytes. Audio MUST be a
single-channel .wav file in 44.1lkHz sample rate and pcm_s16le encoding.
Make sure to review the code example below for the specific format required
when sending and receiving audio.
Format of the response you want to receive. Valid inputs are text or
voice. Defaults to text. If set to voice, clone will respond with base64
encoded audio.
Determines whether or not the response will be the default response format, or
if the clone’s response will be streamed back to the requester token by token
in a stream of Server-Sent Events. If streaming is turned on and
response_type is set to voice, the clone will respond with a stream of
base64 encoded audio snippets. See the audio code example below for more info.
In order for the clone to be able to generate responses it must have a purpose, description, and at least one document all added on the
clone editing page.
If your clone does not yet, you will receive a 403 response from this endpoint warning you to add these before continuing.
The stream response will send the clone response back to the user in a stream of server-sent events
as tokens in the response become available
The format of the events are similar to the Default Response except:
There is one extra field in the stream response type called current_token if response_type == text. audio_chunk if response_type == voice.
If response_type is set to text, current_token will be text. If response_type is set to voice, audio_chunk will be a chunk of base64 encoded audio.
The clone_response field is null while the response is still generating. The response event will include the full details at the end of the stream in the last event
View the Example Stream Response on the sidebar to see an example
Example Python code to accept a stream of server-sent events
import osimport jsonimport requests# The base url for the API (fill in your actual base url here)base_url = "https://api.delphi.ai"# The endpoint pathendpoint = "/api/clone/generate_response"# Combine base url and endpointurl = base_url + endpoint# Your parameters (replace with actual parameters)params = { 'conversation_id': '<my_convo_id>', 'user_message': 'Hello my clone friend', 'slug': 'my-test-clone', 'stream': True}# Your API keyapi_key = os.getenv("DELPHI_API_KEY")# Headersheaders = { 'x-api-key': api_key}# Making a POST requestresponse = requests.post(url, json=params, headers=headers, stream=True)response_text = ""# Process the stream of server-sent eventsif response.status_code == 200: print("Stream started. Processing tokens...") for line in response.iter_lines(): if line: decoded_line = line.decode("utf-8") if decoded_line.startswith("data:"): event_data = decoded_line[6:] event = json.loads(event_data) current_token = event.get("current_token") if current_token == "[DONE]": print(decoded_line) print(f"Stream finished. Final response: {response_text}") break else: print(f"Current token: '{current_token}'") response_text += current_tokenelse: print(f"Error: {response.status_code}") print(response.text)