Example: Chat Completions with Together AI
Example: Chat Completions with Together AI
Use the VoxEngine OpenAI Chat Completions client with Together AI’s OpenAI-compatible API.
For the complete documentation index, see llms.txt.
Overview
This full-cascade example answers an inbound call, transcribes caller speech with Voximplant ASR, sends the final transcript to Together AI through the OpenAI-compatible Chat Completions interface, and speaks the completed response back into the call.
Use this pattern when you want to keep Voximplant call control, ASR, and TTS in VoxEngine while using a third-party LLM provider that exposes an OpenAI-compatible Chat Completions API.
⬇️ Jump to the Full VoxEngine scenario.
This example:
- answers an inbound call
- transcribes caller speech using Voximplant’s built-in ASR module
- sends each final transcript to Together AI through
OpenAI.createChatCompletionsAPIClient() - logs streamed text deltas
- speaks the completed response back to the caller using Voximplant’s default TTS provider
Prerequisites
- A Together AI account with active billing or credits.
- A serverless Together AI model that supports Chat Completions, for example
meta-llama/Llama-3.3-70B-Instruct-Turbo. - Store the Together AI API key in Voximplant Secrets under
TOGETHER_API_KEY. - Create a Voximplant routing rule that points your test destination to this scenario.
Architecture
How it works
- The scenario reads
TOGETHER_API_KEYfrom Voximplant Secrets. baseUrlpoints the OpenAI Chat Completions client at Together AI’s OpenAI-compatible API root.modeluses a Together AI serverless model name.- VoxEngine ASR turns caller speech into text for the Chat Completions request.
- Streamed content deltas are logged as
===LLM_DELTA===. - The final response is logged as
===LLM_DONE===and played back into the call withcall.say().
Modern Voice AI flows utilize turn detection and more sophisticated speech engines. See the Responses API example for a more advanced flow that utilizes Voximplant’s turn detection and external speech integrations for improved speech quality and interactivity.
Usage highlights
- Create an OpenAI Chat Completions client with
OpenAI.createChatCompletionsAPIClient(...). - Set
baseUrl: "https://api.together.ai/v1"so the VoxEngine OpenAI module sends requests to Together AI. - Use a Together model name in the
modelfield instead of an OpenAI model name. - Keep conversation state in the scenario by appending user and assistant messages to the local
messagesarray. - Use
call.say()for a simple example response path. For lower latency and provider-specific voice selection, use a streaming TTS module instead.
Full VoxEngine scenario
More info
- OpenAI module API: https://voximplant.com/docs/references/voxengine/openai
- ASR module API: https://voximplant.com/docs/references/voxengine/asr
- Voximplant Secrets: /platform/voxengine/secrets
- Together AI documentation: https://docs.together.ai/