OpenAI Assistants API Citation Issue. Works in Playground, Fails in React Native App

Hey everyone,

I’m using the OpenAI Assistants API with a knowledge base, and I’ve run into a strange and super frustrating issue with how citations are handled in my React Native app vs. the OpenAI Playground.

  • In the Playground: Everything works correctly. If the assistant finds relevant information in my knowledge base, it cites a specific document. If it doesn’t find a match, it correctly states that it found nothing in the KB.
  • In my React Native app: The assistant always claims it found something in my knowledge base, even when it shouldn’t have. Even worse, instead of citing the correct document (when it actually does find a match), it always labels the source as the name of my vector store (e.g., "MyApp Tracker Bot Dataset") instead of citing an actual file.

Expected Behavior:

Example response when no knowledge base document is relevant:

"citations": [
  {
    "id": "⚠️",
    "source": "General knowledge on medieval architecture"
  }
]

Example response when a match is found:

"citations": [
  {
    "id": "42",
    "source": "Gothic Structures Reference Guide.pdf"
  }
]

Actual Behavior in React Native App:

Regardless of whether there is a match, the assistant always returns a citation, and the source name is replaced with the vector store name instead of an actual file:

"citations": [
  {
    "id": "999",
    "source": "MyApp Tracker Bot Dataset"
  }
]

Even if I ask a question completely unrelated to the KB, it still claims it found something and uses this incorrect dataset name.

Questions:

  • Is there something different in how the Assistants API handles citations outside of the Playground?
  • Has anyone else experienced this issue where the vector store name gets used as a citation instead of an actual file - and most importantly, figured out a fix?

Hi,

Can you post the code that manages the assistants API calls?

1 Like

Sure! Below is the relevant part of my Assistants API call. I don’t explicitly process citations on the backend, so it looks pretty bare bones since I just pass the assistant’s raw response to the frontend. However, since i’m logging the response directly I can see exactly what the API is returning.

 let threadId = user?.openaiThreadId;
    if (!threadId) {
      const thread = await openai.beta.threads.create();
      threadId = thread.id;
      await prisma.user.update({
        where: { id: Number(userId) },
        data: { openaiThreadId: threadId },
      });
    }

    await openai.beta.threads.messages.create(threadId, {
      role: "user",
      content: input.message,
    });

    const run = await openai.beta.threads.runs.createAndPoll(threadId, {
      assistant_id: ASSISTANT_ID
    });

    if (run.status === "completed") {
      // Get the assistant's response
      const messages = await openai.beta.threads.messages.list(threadId, {
        limit: 1,
        order: "desc",
      });
      const message = messages.data[0];
      console.log('9. Assistant response:', message);