I would like to use my openAI realtime API in a te...
# ask-ai
i
I would like to use my openAI realtime API in a text-only setting for instruction testing. How can I go about this?
t
Thanks for reaching out, Matthew. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to guide you through using your OpenAI Realtime API in a text-only setting for instruction testing. Here’s a simple step-by-step to get you started: 1. Install and configure the OpenAI plugin: First, make sure to install the
livekit-plugins-openai
package and set your OpenAI API key in your environment:
pip install livekit-plugins-openaiOPENAI_API_KEY=your_openai_api_key
This will get everything ready for your API calls. 2. Set text-only modality: When you initialize the
RealtimeModel
, use
modalities=["text"]
. This way, audio is disabled and you can focus solely on text interactions. 3. Use AgentSession for testing: Wrap your testing code in an
async with
block to manage the connection and lifecycle smoothly:
Copy code
async with (
    openai.realtime.RealtimeModel(modalities=["text"]) as rt_llm,
    AgentSession(llm=rt_llm, userdata=userdata) as sess,
):
    await sess.start(YourAgent(userdata=userdata))
    result = await sess.run(user_input="What is the weather like today?")
This keeps things neat and organized. 4. Simulate input and capture responses: You can simulate user input with
session.generate_reply(user_input="...")
and listen for events like
conversation_item_added
to capture the agent’s replies programmatically. This setup is designed to help you test your agent’s instructions easily in a controlled, text-only environment. If you have any questions or need a hand with any step, just let me know—I’m here to help! Sources: OpenAI Realtime API plugin guide | LiveKit docs | Using the Testing Framework with Realtime Models | examples/voice_agents/realtime_load_chat_history.py | Azure OpenAI Realtime API and LiveKit | LiveKit Docs
i
I need to be the user for testing purposes, no simulated input. Is there a template for a text-only front-end I can use?
t
I'm happy to guide you through using the Realtime Playground as a template for a text-only front-end for user testing. Here’s a simple way to get everything set up: 1. Clone the Repository: First, download the Realtime Playground from GitHub. 2. Set Up the Agent: ◦ Head over to the
/agent
directory. ◦ Copy
.env.sample
to
.env
and add your LiveKit and OpenAI credentials there. ◦ Then, install the dependencies and run:
python main.py dev
. 1. Set Up the Web Frontend: ◦ Go to the
/web
directory. ◦ Copy
.env.sample
to
.env.local
and add your credentials. ◦ Install dependencies using
pnpm install
and start it up with
pnpm dev
. ◦ Finally, open
http://localhost:3000
in your browser to see it in action. 1. Enable Text-Only Mode: ◦ In the UI, open the configuration panel. ◦ Select “Text Only” under Modalities. ◦ You’re all set to start interacting via text input! If you want to try things out quickly, you can also use the live demo at realtime-playground.livekit.io and switch to text-only mode instantly. Please don’t hesitate to reach out if you have any questions or need a hand with anything—I’m here to help! Sources: Realtime model plugins | LiveKit Docs | Text and transcriptions | LiveKit docs | web/src/data/presets.ts | OpenAI Realtime API plugin guide | LiveKit docs | examples/other/text_only.py
i
This is what I see when I run the web page via pnpm dev. I do not see any config options, nor do any buttons respond.
t
I'm sorry to hear that the Realtime Playground UI is unresponsive and the configuration options aren’t showing up. Let’s work through some troubleshooting steps together to get things back on track: 1. Check Environment Variables: Please double-check that your
.env.local
file is set up correctly with all the necessary credentials and API keys. This is often a key step. 2. Inspect Browser Console: Try opening your browser’s developer tools and look at the console for any errors or warnings. These messages can give us clues about missing dependencies or configuration hiccups. 3. Debounced Updates: The configuration form updates with a 500ms debounce delay, so after making changes, just give it a moment to register before expecting to see the results. 4. Validation Issues: Make sure all fields in the configuration form are filled out correctly. For instance, temperature values should be between 0.6 and 1.2 to be valid. 5. Reconnect Action: If you’ve adjusted voice settings, sometimes you’ll need to click “Reconnect Now” manually to apply those changes. 6. Mobile Interface: On mobile devices, configuration options might be tucked away in a drawer interface. Be sure you’re accessing the right component to see them. 7. React Context Initialization: If the context didn’t load properly, the UI controls might show up but not work as expected. Restarting the application can help reinitialize everything smoothly. If you’re still having trouble after trying these steps, please don’t hesitate to reach out—I’m here to help you get this resolved! Sources: web/src/components/configuration-form-drawer.tsx | Troubleshooting & Common Issues | livekit/livekit_composite | DeepWiki
i
It looks like this is the basic agent playground. I already have an agent, I need to bootstrap a text based frontend to test it with.
t
To help you get started with a text-based frontend for testing your existing agent, here are a few friendly options you can explore: 1. Use the Agents Playground: This is a convenient, ready-to-use web frontend that supports text-based interaction. You can easily connect to the hosted playground at Agents Playground. Just make sure your agent is running in
dev
mode and set up with the right LiveKit credentials. 2. Build a Custom Frontend: If you’d like something tailored, you can use LiveKit’s client SDKs to create your own text-based frontend. Simply send text input via
TextStream
to the
lk.chat
topic and listen for agent responses on the
lk.transcription
topic. You can find helpful details in the frontend documentation. 3. Test in Terminal: For a quick and simple test, try running your agent in
console
mode: `python myagent.py console`This way, you can chat with your agent directly through the terminal using text input and output. If you have any questions or want to dive deeper into any of these options, just let me know—I’m here to help! Sources: Agents playground | LiveKit Docs | README.md | examples/other/text_only.py | How to Set Up Speech-to-Text Input with Text-Only Output in LiveKit Agents | External data and RAG | LiveKit Docs
i
I only see the usual instructions field in the agents playground. How do I make it operate directly from my backend agent code?
t
Let’s get your Agents Playground connected directly to your custom backend agent! Just follow these simple steps: 1. Run Your Backend Agent: Start your agent in
dev
mode so it can connect smoothly to your LiveKit server. Make sure you’ve set these environment variables: Here’s how you can do it: For Python: `python your_agent.py dev`For Node.js:
node your_agent.js dev
◦
LIVEKIT_URL
(like
wss://your-project.livekit.cloud
) ◦
LIVEKIT_API_KEY
◦
LIVEKIT_API_SECRET
◦ Any other API keys you need for AI services (for example,
OPENAI_API_KEY
) 1. Generate a Room Access Token: Use your LiveKit API credentials to create a participant token that lets you join the room. Here’s a handy JavaScript example:
Copy code
import { AccessToken } from 'livekit-server-sdk';

const API_KEY = process.env.LIVEKIT_API_KEY;
const API_SECRET = process.env.LIVEKIT_API_SECRET;
const roomName = 'your_room_name';

const at = new AccessToken(API_KEY, API_SECRET, {
  identity: 'user_identity',
  ttl: '15m',
});
at.addGrant({
  room: roomName,
  roomJoin: true,
  canPublish: true,
  canPublishData: true,
  canSubscribe: true,
});

const token = at.toJwt();
2. Connect to the Agents Playground: Head over to the Agents Playground or run it locally. Just pop in your
LIVEKIT_URL
and the token you just generated into the fields, then hit "Connect." This setup will let the playground chat directly with your backend agent. If anything feels unclear or you’d like a hand with any step, just let me know—I’m here to help! Sources: examples/README.md | Agents playground | LiveKit Docs | Voice AI quickstart | LiveKit docs | README.md | complex-agents/note-taking-assistant/README.md