# Realtime API with Knowledge Base

**URL:** <https://community.openai.com/t/realtime-api-with-knowledge-base/1017783>\
**Category:** API\
**Tags:** vector-db, realtime, api-realtime-speech\
**Created:** [November 14, 2024, 12:14pm UTC](https://community.openai.com/t/realtime-api-with-knowledge-base/1017783 "2024-11-14T12:14:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hayamione](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/hayamione/32/497742_2.png) [@hayamione](https://community.openai.com/u/hayamione)\
**Post date:** [November 14, 2024, 12:14pm UTC](https://community.openai.com/t/realtime-api-with-knowledge-base/1017783/1 "2024-11-14T12:14:33Z")

</div>

I am working on the code of realtime API twilio integration. I want to call here an external api or use open ai knowledge base / vector store or db with it.  
Like user ask for some query and that will respond from its knowledge base  
How can I implement that? step by step.

---

<div class="post-metadata">

**Author:** ![ivan-luchkin-u](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/ivan-luchkin-u/32/146580_2.png) [@ivan-luchkin-u](https://community.openai.com/u/ivan-luchkin-u)\
**Post date:** [November 14, 2024, 2:19pm UTC](https://community.openai.com/t/realtime-api-with-knowledge-base/1017783/2 "2024-11-14T14:19:01Z")

</div>

Add some functions in your realtime session configuration or per-request. When the model calls a function, have this function contain some query-like info from the user. You can then use this information to call any API’s or queries to whatever you like. If the latency allows, you can take the data acquired by this retrieval and send the response back to the model by specifying that this is a response to the function call

---

<div class="post-metadata">

**Author:** ![hayamione](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/hayamione/32/497742_2.png) [@hayamione](https://community.openai.com/u/hayamione)\
**Post date:** [November 15, 2024, 12:45pm UTC](https://community.openai.com/t/realtime-api-with-knowledge-base/1017783/3 "2024-11-15T12:45:58Z")

</div>

and how do I use functions with realtime API  
Like this is normal code  
// Control initial session with OpenAI  
const initializeSession = () =\> {  
const sessionUpdate = {  
type: “session.update”,  
session: {  
turn\_detection: { type: “server\_vad” },  
input\_audio\_format: “g711\_ulaw”,  
output\_audio\_format: “g711\_ulaw”,  
voice: VOICE,  
instructions: SYSTEM\_MESSAGE,  
modalities: [“text”, “audio”],  
temperature: 0.8,  
},  
};

```
  console.log("Sending session update:", JSON.stringify(sessionUpdate));
  openAiWs.send(JSON.stringify(sessionUpdate));

```

How to use openAI functions

---

<div class="post-metadata">

**Author:** ![ivan-luchkin-u](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/ivan-luchkin-u/32/146580_2.png) [@ivan-luchkin-u](https://community.openai.com/u/ivan-luchkin-u)\
**Post date:** [November 15, 2024, 12:47pm UTC](https://community.openai.com/t/realtime-api-with-knowledge-base/1017783/4 "2024-11-15T12:47:09Z")

</div>

All the necessary information is provided in the [API reference](https://platform.openai.com/docs/api-reference/realtime-client-events/session/update)
