Ai apiRag mode

Call the Inkeep RAG API with an HTTP Request

The Inkeep RAG API provides structured documents from your knowledge base. This page shows how to make direct HTTP requests to the API. Please ensure you have an API key (don't have one? Get one here).

Request Format

POST https://api.inkeep.com/v1/chat/completions
Content-Type: application/json
Authorization: Bearer YOUR_INKEEP_API_KEY
 
{
  "model": "inkeep-rag",
  "messages": [
    {
      "role": "user",
      "content": "How do I get started?"
    }
  ],
  "response_format": {
    "type": "json_object"
  }
}

Response Format

{
  "id": "chatcmpl-123abc",
  "object": "chat.completion",
  "created": 1677858242,
  "model": "inkeep-rag",
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "{\"content\":[{\"type\":\"document\",\"record_type\":\"Documentation\",\"url\":\"https://docs.inkeep.com/ui-components/js-snippet/embedded-search-and-chat\",\"title\":\"Embedded Search and Chat (JS) - Inkeep\",\"source\":{\"type\":\"content\",\"content\":[{\"type\":\"text\",\"text\":\"## Quick start\\n\\nAdd the below `<script>` tag to the `<head>` or `<body>` of your website.\"}]}},{\"type\":\"document\",\"record_type\":\"Documentation\",\"url\":\"https://docs.inkeep.com/projects/overview\",\"title\":\"Projects Overview - Inkeep\",\"source\":{\"type\":\"content\",\"content\":[{\"type\":\"text\",\"text\":\"# Projects Overview\\n\\nProjects are the core organizational unit in Inkeep. Each project represents a distinct AI assistant with its own knowledge base, settings, and integrations.\"}]}}]}"
      },
      "finish_reason": "stop",
      "index": 0
    }
  ]
}

Content Example

The sources are under content as stringified JSON. The parsed result looks like:

{
  "content": [
    {
      "type": "document",
      "record_type": "documentation",
      "url": "https://docs.inkeep.com/ui-components/js-snippet/embedded-search-and-chat",
      "title": "Embedded Search and Chat (JS) - Inkeep",
      "source": {
        "type": "content",
        "content": [
          {
            "type": "text",
            "text": "## Quick start\n\nAdd the below `<script>` tag to the `<head>` or `<body>` of your website."
          }
        ]
      }
    },
    {
      "type": "document",
      "record_type": "documentation", 
      "url": "https://docs.inkeep.com/projects/overview",
      "title": "Projects Overview - Inkeep",
      "source": {
        "type": "content",
        "content": [
          {
            "type": "text",
            "text": "# Projects Overview\n\nProjects are the core organizational unit in Inkeep. Each project represents a distinct AI assistant with its own knowledge base, settings, and integrations."
          }
        ]
      }
    }
  ]
}

Content Schema

The RAG API returns a JSON object with an array of documents in the content field. Each document has the following structure:

FieldTypeDescription
typestringThe type of the document, typically "document"
record_typestringThe source of the document (e.g., "Documentation", "GitHub Issue", "Forum")
urlstringThe URL where the document can be found
titlestringThe title of the document
sourceobjectContains the content of the document (see Source Entity for details)
contextstringOptional additional context about the document

Source Entity

The source field contains the actual content of the document in a structured format. It has the following structure:

FieldTypeDescription
typestringType of the source, typically "content"
contentarrayArray of content blocks

Each item in the content array has the following structure:

FieldTypeDescription
typestringType of content block (e.g., "text")
textstringThe actual text content when type is "text"
media_typestringOptional media type of the content (e.g., "text/plain")
datastringOptional alternative data field for content

Document Source Types

The RAG API can return documents from various sources:

Record TypeDescription
documentationOfficial documentation pages
siteContent from your website
discourse_postDiscourse Forum Posts
github_issueGitHub issues or pull requests
github_discussionGitHub Discussions
stackoverflow_questionStackOverflow Questions and Answers
discord_forum_postDiscord Forum Posts
discord_messageDiscord Threads/Messages
custom_question_answerCustom FAQ Added to the knowledge base

Example Usage

Here's an example of how to call the RAG API using curl:

curl -X POST https://api.inkeep.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $INKEEP_API_KEY" \
  -d '{
    "model": "inkeep-rag",
    "messages": [
      {
        "role": "user",
        "content": "How do I get started?"
      }
    ],
    "response_format": {
      "type": "json_object"
    }
  }'

Example Source Entity

Here's an example of a source entity from the response:

"source": {
  "type": "content",
  "content": [
    {
      "type": "text",
      "text": "## Quick start\n\nAdd the below `<script>` tag to the `<head>` or `<body>` of your website."
    },
    {
      "type": "text",
      "text": "```html\n<script>\n  (function() {\n    var inkeepConfig = {\n      apiKey: \"YOUR_API_KEY\",\n      baseSettings: {\n        organizationDisplayName: \"Your Organization\",\n        primaryBrandColor: \"#26D6FF\"\n      }\n    };\n    var script = document.createElement(\"script\");\n    script.src = \"https://cdn.inkeep.com/embed.js\";\n    script.setAttribute(\"data-inkeep\", JSON.stringify(inkeepConfig));\n    document.head.appendChild(script);\n  })();\n</script>\n```"
    }
  ]
}

Processing the Response

To process the response, you'll need to:

  1. Parse the JSON response
  2. Extract the content field from the message.content JSON string
  3. Process each document in the content array

This will give you structured access to the documents retrieved from your knowledge base.

On this page