HTTP API Reference

Context API reference

Build knowledge bases from file uploads, website crawls, and Sanity datasets, then read, triage, and steer what they produce over HTTP.

Build knowledge bases from your content (file uploads, website crawls, and Sanity datasets), then read, triage, and steer what they produce.

Authentication

Send an organization API token with Context access, or a Sanity user token, in the Authorization: Bearer <token> header. Project API tokens aren't accepted.

Operations under a knowledge base check one of two levels of access:

  • Read access: the sanity.knowledge-base.read grant.
  • Update access: any one of sanity.knowledge-base.update, sanity.knowledge-base.entries.update, sanity.knowledge-base.issues.update or sanity.knowledge-base.instructions.update.

Each operation says which level it needs, or names the grant it checks.

API versions

Every path starts with the API version, vYYYY-MM-DD. Use v2026-11-03. Earlier versions keep behavior that has since changed: before v2026-11-03, MCP endpoints accept their configuration as query parameters.

Errors

An error returns a JSON body with a stable code and a readable message. Branch on code. Operation descriptions don't repeat the errors below, which any operation can return where they apply:

  • 401: no token (missingCredential), a malformed Authorization header (invalidCredential), or a token without access to the organization (organizationAccessDenied).
  • 404 with code knowledgeBaseNotFound: the knowledge base doesn't exist, or the token can't access its organization. A knowledge base ID never confirms that it exists.
  • 403 with code knowledgeBaseAccessDenied: the token lacks the access the operation needs. fields.required lists the grants that would allow it.
  • 400 with code validationError: the request doesn't match the schema.
  • 502 with code accessCheckFailed: the token's access couldn't be checked. Try again.

A 503 response carries a Retry-After header.

Entries, issues, and instructions

A knowledge base keeps its entries, issues, and instructions as sanity.context.* documents in your organization's document store, alongside MCP endpoint configurations and recorded conversations. No operation lists or returns these documents: query them with GROQ through client.context.fetch in @sanity/client, and use these operations to change them. See Knowledge Bases.

Base API server URL

Production

https://api.sanity.io

knowledge-bases

Create, configure, and build knowledge bases.

List knowledge bases

get/{apiVersion}/context/knowledge-bases

Returns every knowledge base in the organization set by organizationId, including ones your token can't read or update. Drafts are left out unless you set includeDrafts to true. Results are cursor-paginated, newest first. Requires membership in the organization.

Path parameters

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Query parameters

  • cursorstring

    The nextCursor value from the previous page. Omit it to get the first page.

  • limitintegerdefault: 50

    The maximum number of items to return.

  • organizationIdstringrequired

    The organization to list knowledge bases for.

  • Set to true to also list the organization's drafts, which have state set to draft. Drafts count toward the plan's knowledge base limit, and createdBy says who started each one.

Responses

200

A page of knowledge bases.

  • dataarrayrequired

    The items on this page.

    Show child attributes
    items
    • idstring (uuid)required

      An internal UUID for the knowledge base, still accepted wherever a knowledgeBaseId is expected. Use publicId instead.

    • publicIdstringrequired

      The knowledge base's ID, such as kb3do82whm. Store this one, and pass it as knowledgeBaseId in paths and filters. Treat it as an opaque string.

    • organizationIdstringrequired

      The ID of the organization that owns the knowledge base.

    • titlestringrequired

      The knowledge base's title.

    • descriptionstringrequired

      A short description of what the knowledge base covers.

    • statestringrequired

      The knowledge base's state. draft: still being set up, so it can't be built yet. created: not built yet. ready: built. Open issues and failed builds don't change the state. To check for open issues, use openIssueCount. To check for a running build, use isBuilding.

    • activeJobIdrequired

      The job ID of the most recent build, including builds Sanity Context started on its own. null if no build has started, or if the most recent build was cancelled or failed to start. Check its progress with GET .../jobs/{jobId}.

      Show child attributes
      • string
    • isBuildingbooleanrequired

      Whether a build is running now.

    • Progress of the most recent build, by stage. null until a build reports progress. It can briefly belong to an earlier build, so use it only when its jobId matches activeJobId.

      Show child attributes
      • jobIdstringrequired

        The ID of the build job this progress belongs to.

      • stagesarrayrequired

        Every stage this build runs, in the order it runs them, with each stage's progress.

        Show child attributes
        items
        • idstringrequired

          The stage's ID, such as map or write. Which stages a build runs changes between builds and knowledge bases, so treat it as an open string and handle IDs you don't recognize.

        • weightnumberrequired

          The stage's share of the whole build, from 0 to 1. The weights of a build's stages sum to 1.

        • statusstringrequired

          The stage's status. pending: not started. running: in progress. done: finished. failed: the stage ended without finishing, because the build ended first or, for the conflict stages, because the check failed and the build went on without it.

        • unitsobject

          The stage's progress counts. Absent when the stage hasn't reported counts.

          Show child attributes
          • unitstringrequired

            What done and total count: sources, groups of related content, entries, or rounds of final fixes. A rounds stage has no total.

          • doneintegerrequired

            How many units the stage has finished.

          • totalinteger

            How many units the stage will process. Absent when unit is rounds.

    • When a refresh last checked the knowledge base for changes, whether or not anything changed. null until the first refresh.

      Show child attributes
      • string (date-time)
    • When the content last changed: the time of the most recent successful build. null if the knowledge base has never built.

      Show child attributes
      • string (date-time)
    • hasPendingChangesbooleanrequired

      Whether sources were added, changed, or removed since the last successful build. A change a check already reviewed without filing an issue, or that a dismissed issue covered, no longer counts. Always false before the first build.

    • Counts of sources added, changed, and removed since the last successful build, excluding changes a check already reviewed without filing an issue or that a dismissed issue covered. Only GET .../knowledge-bases/{knowledgeBaseId} computes it. null in list responses and before the first build.

      Show child attributes
      • addedintegerrequired

        Sources added since the last successful build, including sources no successful build has included yet.

      • changedintegerrequired

        Sources whose content changed since the last successful build.

      • removedintegerrequired

        Sources that recent refreshes no longer find.

    • pipelineOutdatedbooleanrequired

      Whether Sanity Context has improved how it builds knowledge bases since the last successful build. Rebuild to apply the improvements. Always false before the first build.

    • rebuildFaultrequired

      Set when a rebuild Sanity Context started on its own, to bring entries up to date, failed. Rebuild to try again. null when there's no fault. Starting a build clears it, and so does a refresh that finds the entries up to date.

      Show child attributes
      • messagestringrequired

        What went wrong, written to show to users.

      • atstring (date-time)required

        When the rebuild failed.

    • pendingSourcesobjectrequired

      The source changes waiting for POST .../apply: sources added that the knowledge base doesn't use yet, which sync meanwhile, sources removed that it uses until then, and files sources with a new file it doesn't use yet. Before the first build nothing waits, since the first build applies them.

      Show child attributes
      • addedintegerrequired

        How many sources were added to the knowledge base.

      • removedintegerrequired

        How many sources were removed from the knowledge base.

      • replacedintegerrequired

        How many files sources got a new file.

    • hasWebSourcebooleanrequired

      Whether the knowledge base has at least one website source.

    • webSourceLimitintegerrequired

      The maximum number of website sources the knowledge base can have. Adding one more returns 409 with code webSourceRootLimitExceeded.

    • hasDatasetSourcebooleanrequired

      Whether the knowledge base has at least one Sanity dataset source.

    • hasFileSourcebooleanrequired

      Whether the knowledge base has at least one uploaded file source.

    • sourceChunksintegerrequired

      The number of source chunks in the live documents of the knowledge base's sources, whether or not they have been built: the sum of its sources' chunkCount. It includes the chunks counted by excludedSourceChunks, and those of documents whose content another document repeats, which builds skip. Documents still being converted add theirs once converted.

    • excludedSourceChunksintegerrequired

      The number of source chunks in documents the organization's source chunk limit left out of builds. They count toward no limit, and the next build includes them once the limit has room.

    • Why a build request would be denied right now, or null if you can build. Only GET .../knowledge-bases/{knowledgeBaseId} checks it. List and create responses always return null.

      Show child attributes
      • codestringrequired

        A stable code for the restriction, such as planLimitReached.

      • messagestringrequired

        A readable explanation that you can show to users.

    • refreshInFlightbooleanrequired

      Whether a refresh is running now. While it's true, a new refresh request makes the running one run once more when it ends instead of starting another. Only GET .../knowledge-bases/{knowledgeBaseId} computes it, so list responses return false.

    • openIssueCountintegerrequired

      The number of open issues waiting for review. Always 0 before the first build.

    • instructionCountintegerrequired

      The number of active instructions for the knowledge base.

    • createdByrequired

      Who created the knowledge base. null if unknown.

      Show child attributes
      • idrequired

        The Sanity user ID, or sanity-system when Sanity Context made the change. null if unknown.

        Show child attributes
        • string
      • displayNamerequired

        The user's name when the action happened. null if unknown. For the current name, look up the user by id.

        Show child attributes
        • string
    • createdAtstring (date-time)required

      When the knowledge base was created.

    • updatedAtstring (date-time)required

      When the knowledge base was last updated.

  • nextCursorrequired

    The cursor for the next page. Pass it as cursor to get more results. null when there are no more pages.

    Show child attributes
    • string

Create a knowledge base

post/{apiVersion}/context/knowledge-bases

Creates a knowledge base in your organization. To add content to it, add a source. Set draft to true to create a draft, which needs no title or description until you finish it. A token without the create grant gets 403 with code knowledgeBaseCreateAccessDenied. If the organization has reached its plan's knowledge base limit, drafts included, the request returns 403 with code planLimitReached. If your organization's Context document store can't be used, the request returns 503 with code contextStoreUnavailable and you can retry. Requires the sanity.knowledge-base.create grant.

Path parameters

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Header parameters

  • A unique value, such as a UUID, that makes retries safe. A retry with the same key and body returns the first response instead of repeating the work.

Request body application/json

  • organizationIdstringrequired

    The ID of the organization to create the knowledge base in.

  • titlestring

    The knowledge base's title. Required unless draft is true.

  • A short description of what the knowledge base covers. Required unless draft is true.

  • draftboolean

    Whether to create the knowledge base as a draft. You can add sources to a draft, and they sync right away, but you can't build it, and the list leaves it out unless you set includeDrafts to true. A draft counts toward your plan's knowledge base limit. To finish it, update it with draft set to false.

Responses

201

A knowledge base and its current state.

  • idstring (uuid)required

    An internal UUID for the knowledge base, still accepted wherever a knowledgeBaseId is expected. Use publicId instead.

  • publicIdstringrequired

    The knowledge base's ID, such as kb3do82whm. Store this one, and pass it as knowledgeBaseId in paths and filters. Treat it as an opaque string.

  • organizationIdstringrequired

    The ID of the organization that owns the knowledge base.

  • titlestringrequired

    The knowledge base's title.

  • descriptionstringrequired

    A short description of what the knowledge base covers.

  • statestringrequired

    The knowledge base's state. draft: still being set up, so it can't be built yet. created: not built yet. ready: built. Open issues and failed builds don't change the state. To check for open issues, use openIssueCount. To check for a running build, use isBuilding.

  • activeJobIdrequired

    The job ID of the most recent build, including builds Sanity Context started on its own. null if no build has started, or if the most recent build was cancelled or failed to start. Check its progress with GET .../jobs/{jobId}.

    Show child attributes
    • string
  • isBuildingbooleanrequired

    Whether a build is running now.

  • Progress of the most recent build, by stage. null until a build reports progress. It can briefly belong to an earlier build, so use it only when its jobId matches activeJobId.

    Show child attributes
    • jobIdstringrequired

      The ID of the build job this progress belongs to.

    • stagesarrayrequired

      Every stage this build runs, in the order it runs them, with each stage's progress.

      Show child attributes
      items
      • idstringrequired

        The stage's ID, such as map or write. Which stages a build runs changes between builds and knowledge bases, so treat it as an open string and handle IDs you don't recognize.

      • weightnumberrequired

        The stage's share of the whole build, from 0 to 1. The weights of a build's stages sum to 1.

      • statusstringrequired

        The stage's status. pending: not started. running: in progress. done: finished. failed: the stage ended without finishing, because the build ended first or, for the conflict stages, because the check failed and the build went on without it.

      • unitsobject

        The stage's progress counts. Absent when the stage hasn't reported counts.

        Show child attributes
        • unitstringrequired

          What done and total count: sources, groups of related content, entries, or rounds of final fixes. A rounds stage has no total.

        • doneintegerrequired

          How many units the stage has finished.

        • totalinteger

          How many units the stage will process. Absent when unit is rounds.

  • When a refresh last checked the knowledge base for changes, whether or not anything changed. null until the first refresh.

    Show child attributes
    • string (date-time)
  • When the content last changed: the time of the most recent successful build. null if the knowledge base has never built.

    Show child attributes
    • string (date-time)
  • hasPendingChangesbooleanrequired

    Whether sources were added, changed, or removed since the last successful build. A change a check already reviewed without filing an issue, or that a dismissed issue covered, no longer counts. Always false before the first build.

  • Counts of sources added, changed, and removed since the last successful build, excluding changes a check already reviewed without filing an issue or that a dismissed issue covered. Only GET .../knowledge-bases/{knowledgeBaseId} computes it. null in list responses and before the first build.

    Show child attributes
    • addedintegerrequired

      Sources added since the last successful build, including sources no successful build has included yet.

    • changedintegerrequired

      Sources whose content changed since the last successful build.

    • removedintegerrequired

      Sources that recent refreshes no longer find.

  • pipelineOutdatedbooleanrequired

    Whether Sanity Context has improved how it builds knowledge bases since the last successful build. Rebuild to apply the improvements. Always false before the first build.

  • rebuildFaultrequired

    Set when a rebuild Sanity Context started on its own, to bring entries up to date, failed. Rebuild to try again. null when there's no fault. Starting a build clears it, and so does a refresh that finds the entries up to date.

    Show child attributes
    • messagestringrequired

      What went wrong, written to show to users.

    • atstring (date-time)required

      When the rebuild failed.

  • pendingSourcesobjectrequired

    The source changes waiting for POST .../apply: sources added that the knowledge base doesn't use yet, which sync meanwhile, sources removed that it uses until then, and files sources with a new file it doesn't use yet. Before the first build nothing waits, since the first build applies them.

    Show child attributes
    • addedintegerrequired

      How many sources were added to the knowledge base.

    • removedintegerrequired

      How many sources were removed from the knowledge base.

    • replacedintegerrequired

      How many files sources got a new file.

  • hasWebSourcebooleanrequired

    Whether the knowledge base has at least one website source.

  • webSourceLimitintegerrequired

    The maximum number of website sources the knowledge base can have. Adding one more returns 409 with code webSourceRootLimitExceeded.

  • hasDatasetSourcebooleanrequired

    Whether the knowledge base has at least one Sanity dataset source.

  • hasFileSourcebooleanrequired

    Whether the knowledge base has at least one uploaded file source.

  • sourceChunksintegerrequired

    The number of source chunks in the live documents of the knowledge base's sources, whether or not they have been built: the sum of its sources' chunkCount. It includes the chunks counted by excludedSourceChunks, and those of documents whose content another document repeats, which builds skip. Documents still being converted add theirs once converted.

  • excludedSourceChunksintegerrequired

    The number of source chunks in documents the organization's source chunk limit left out of builds. They count toward no limit, and the next build includes them once the limit has room.

  • Why a build request would be denied right now, or null if you can build. Only GET .../knowledge-bases/{knowledgeBaseId} checks it. List and create responses always return null.

    Show child attributes
    • codestringrequired

      A stable code for the restriction, such as planLimitReached.

    • messagestringrequired

      A readable explanation that you can show to users.

  • refreshInFlightbooleanrequired

    Whether a refresh is running now. While it's true, a new refresh request makes the running one run once more when it ends instead of starting another. Only GET .../knowledge-bases/{knowledgeBaseId} computes it, so list responses return false.

  • openIssueCountintegerrequired

    The number of open issues waiting for review. Always 0 before the first build.

  • instructionCountintegerrequired

    The number of active instructions for the knowledge base.

  • createdByrequired

    Who created the knowledge base. null if unknown.

    Show child attributes
    • idrequired

      The Sanity user ID, or sanity-system when Sanity Context made the change. null if unknown.

      Show child attributes
      • string
    • displayNamerequired

      The user's name when the action happened. null if unknown. For the current name, look up the user by id.

      Show child attributes
      • string
  • createdAtstring (date-time)required

    When the knowledge base was created.

  • updatedAtstring (date-time)required

    When the knowledge base was last updated.

Get a knowledge base

get/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}

Returns a knowledge base's metadata and state. knowledgeBaseId accepts the public ID (kb...) or the UUID, and you don't need to pass an organization. Any member of the knowledge base's organization can read it, even without read access to the knowledge base. To read the built entries, query sanity.context.entry documents with GROQ from your organization's document store. Requires membership in the knowledge base's organization.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Responses

200

A knowledge base and its current state.

  • idstring (uuid)required

    An internal UUID for the knowledge base, still accepted wherever a knowledgeBaseId is expected. Use publicId instead.

  • publicIdstringrequired

    The knowledge base's ID, such as kb3do82whm. Store this one, and pass it as knowledgeBaseId in paths and filters. Treat it as an opaque string.

  • organizationIdstringrequired

    The ID of the organization that owns the knowledge base.

  • titlestringrequired

    The knowledge base's title.

  • descriptionstringrequired

    A short description of what the knowledge base covers.

  • statestringrequired

    The knowledge base's state. draft: still being set up, so it can't be built yet. created: not built yet. ready: built. Open issues and failed builds don't change the state. To check for open issues, use openIssueCount. To check for a running build, use isBuilding.

  • activeJobIdrequired

    The job ID of the most recent build, including builds Sanity Context started on its own. null if no build has started, or if the most recent build was cancelled or failed to start. Check its progress with GET .../jobs/{jobId}.

    Show child attributes
    • string
  • isBuildingbooleanrequired

    Whether a build is running now.

  • Progress of the most recent build, by stage. null until a build reports progress. It can briefly belong to an earlier build, so use it only when its jobId matches activeJobId.

    Show child attributes
    • jobIdstringrequired

      The ID of the build job this progress belongs to.

    • stagesarrayrequired

      Every stage this build runs, in the order it runs them, with each stage's progress.

      Show child attributes
      items
      • idstringrequired

        The stage's ID, such as map or write. Which stages a build runs changes between builds and knowledge bases, so treat it as an open string and handle IDs you don't recognize.

      • weightnumberrequired

        The stage's share of the whole build, from 0 to 1. The weights of a build's stages sum to 1.

      • statusstringrequired

        The stage's status. pending: not started. running: in progress. done: finished. failed: the stage ended without finishing, because the build ended first or, for the conflict stages, because the check failed and the build went on without it.

      • unitsobject

        The stage's progress counts. Absent when the stage hasn't reported counts.

        Show child attributes
        • unitstringrequired

          What done and total count: sources, groups of related content, entries, or rounds of final fixes. A rounds stage has no total.

        • doneintegerrequired

          How many units the stage has finished.

        • totalinteger

          How many units the stage will process. Absent when unit is rounds.

  • When a refresh last checked the knowledge base for changes, whether or not anything changed. null until the first refresh.

    Show child attributes
    • string (date-time)
  • When the content last changed: the time of the most recent successful build. null if the knowledge base has never built.

    Show child attributes
    • string (date-time)
  • hasPendingChangesbooleanrequired

    Whether sources were added, changed, or removed since the last successful build. A change a check already reviewed without filing an issue, or that a dismissed issue covered, no longer counts. Always false before the first build.

  • Counts of sources added, changed, and removed since the last successful build, excluding changes a check already reviewed without filing an issue or that a dismissed issue covered. Only GET .../knowledge-bases/{knowledgeBaseId} computes it. null in list responses and before the first build.

    Show child attributes
    • addedintegerrequired

      Sources added since the last successful build, including sources no successful build has included yet.

    • changedintegerrequired

      Sources whose content changed since the last successful build.

    • removedintegerrequired

      Sources that recent refreshes no longer find.

  • pipelineOutdatedbooleanrequired

    Whether Sanity Context has improved how it builds knowledge bases since the last successful build. Rebuild to apply the improvements. Always false before the first build.

  • rebuildFaultrequired

    Set when a rebuild Sanity Context started on its own, to bring entries up to date, failed. Rebuild to try again. null when there's no fault. Starting a build clears it, and so does a refresh that finds the entries up to date.

    Show child attributes
    • messagestringrequired

      What went wrong, written to show to users.

    • atstring (date-time)required

      When the rebuild failed.

  • pendingSourcesobjectrequired

    The source changes waiting for POST .../apply: sources added that the knowledge base doesn't use yet, which sync meanwhile, sources removed that it uses until then, and files sources with a new file it doesn't use yet. Before the first build nothing waits, since the first build applies them.

    Show child attributes
    • addedintegerrequired

      How many sources were added to the knowledge base.

    • removedintegerrequired

      How many sources were removed from the knowledge base.

    • replacedintegerrequired

      How many files sources got a new file.

  • hasWebSourcebooleanrequired

    Whether the knowledge base has at least one website source.

  • webSourceLimitintegerrequired

    The maximum number of website sources the knowledge base can have. Adding one more returns 409 with code webSourceRootLimitExceeded.

  • hasDatasetSourcebooleanrequired

    Whether the knowledge base has at least one Sanity dataset source.

  • hasFileSourcebooleanrequired

    Whether the knowledge base has at least one uploaded file source.

  • sourceChunksintegerrequired

    The number of source chunks in the live documents of the knowledge base's sources, whether or not they have been built: the sum of its sources' chunkCount. It includes the chunks counted by excludedSourceChunks, and those of documents whose content another document repeats, which builds skip. Documents still being converted add theirs once converted.

  • excludedSourceChunksintegerrequired

    The number of source chunks in documents the organization's source chunk limit left out of builds. They count toward no limit, and the next build includes them once the limit has room.

  • Why a build request would be denied right now, or null if you can build. Only GET .../knowledge-bases/{knowledgeBaseId} checks it. List and create responses always return null.

    Show child attributes
    • codestringrequired

      A stable code for the restriction, such as planLimitReached.

    • messagestringrequired

      A readable explanation that you can show to users.

  • refreshInFlightbooleanrequired

    Whether a refresh is running now. While it's true, a new refresh request makes the running one run once more when it ends instead of starting another. Only GET .../knowledge-bases/{knowledgeBaseId} computes it, so list responses return false.

  • openIssueCountintegerrequired

    The number of open issues waiting for review. Always 0 before the first build.

  • instructionCountintegerrequired

    The number of active instructions for the knowledge base.

  • createdByrequired

    Who created the knowledge base. null if unknown.

    Show child attributes
    • idrequired

      The Sanity user ID, or sanity-system when Sanity Context made the change. null if unknown.

      Show child attributes
      • string
    • displayNamerequired

      The user's name when the action happened. null if unknown. For the current name, look up the user by id.

      Show child attributes
      • string
  • createdAtstring (date-time)required

    When the knowledge base was created.

  • updatedAtstring (date-time)required

    When the knowledge base was last updated.

Update a knowledge base

patch/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}

Updates the title or the description, or finishes a draft (draft: false). Fields equal to their current value are ignored, so sending the current values changes nothing. Finishing a draft with no title returns 422 with code draftTitleRequired. How often a website or dataset syncs is set on the source, with PATCH .../sources/{sourceId}. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Request body application/json

  • titlestring

    The knowledge base's new title.

  • The knowledge base's new description.

  • draftboolean

    Set to false to finish a draft, so it can be built and is listed with your other knowledge bases. The knowledge base needs a title, sent here or set before. Ignored when the knowledge base isn't a draft. A finished knowledge base can't become a draft again.

Responses

200

A knowledge base and its current state.

  • idstring (uuid)required

    An internal UUID for the knowledge base, still accepted wherever a knowledgeBaseId is expected. Use publicId instead.

  • publicIdstringrequired

    The knowledge base's ID, such as kb3do82whm. Store this one, and pass it as knowledgeBaseId in paths and filters. Treat it as an opaque string.

  • organizationIdstringrequired

    The ID of the organization that owns the knowledge base.

  • titlestringrequired

    The knowledge base's title.

  • descriptionstringrequired

    A short description of what the knowledge base covers.

  • statestringrequired

    The knowledge base's state. draft: still being set up, so it can't be built yet. created: not built yet. ready: built. Open issues and failed builds don't change the state. To check for open issues, use openIssueCount. To check for a running build, use isBuilding.

  • activeJobIdrequired

    The job ID of the most recent build, including builds Sanity Context started on its own. null if no build has started, or if the most recent build was cancelled or failed to start. Check its progress with GET .../jobs/{jobId}.

    Show child attributes
    • string
  • isBuildingbooleanrequired

    Whether a build is running now.

  • Progress of the most recent build, by stage. null until a build reports progress. It can briefly belong to an earlier build, so use it only when its jobId matches activeJobId.

    Show child attributes
    • jobIdstringrequired

      The ID of the build job this progress belongs to.

    • stagesarrayrequired

      Every stage this build runs, in the order it runs them, with each stage's progress.

      Show child attributes
      items
      • idstringrequired

        The stage's ID, such as map or write. Which stages a build runs changes between builds and knowledge bases, so treat it as an open string and handle IDs you don't recognize.

      • weightnumberrequired

        The stage's share of the whole build, from 0 to 1. The weights of a build's stages sum to 1.

      • statusstringrequired

        The stage's status. pending: not started. running: in progress. done: finished. failed: the stage ended without finishing, because the build ended first or, for the conflict stages, because the check failed and the build went on without it.

      • unitsobject

        The stage's progress counts. Absent when the stage hasn't reported counts.

        Show child attributes
        • unitstringrequired

          What done and total count: sources, groups of related content, entries, or rounds of final fixes. A rounds stage has no total.

        • doneintegerrequired

          How many units the stage has finished.

        • totalinteger

          How many units the stage will process. Absent when unit is rounds.

  • When a refresh last checked the knowledge base for changes, whether or not anything changed. null until the first refresh.

    Show child attributes
    • string (date-time)
  • When the content last changed: the time of the most recent successful build. null if the knowledge base has never built.

    Show child attributes
    • string (date-time)
  • hasPendingChangesbooleanrequired

    Whether sources were added, changed, or removed since the last successful build. A change a check already reviewed without filing an issue, or that a dismissed issue covered, no longer counts. Always false before the first build.

  • Counts of sources added, changed, and removed since the last successful build, excluding changes a check already reviewed without filing an issue or that a dismissed issue covered. Only GET .../knowledge-bases/{knowledgeBaseId} computes it. null in list responses and before the first build.

    Show child attributes
    • addedintegerrequired

      Sources added since the last successful build, including sources no successful build has included yet.

    • changedintegerrequired

      Sources whose content changed since the last successful build.

    • removedintegerrequired

      Sources that recent refreshes no longer find.

  • pipelineOutdatedbooleanrequired

    Whether Sanity Context has improved how it builds knowledge bases since the last successful build. Rebuild to apply the improvements. Always false before the first build.

  • rebuildFaultrequired

    Set when a rebuild Sanity Context started on its own, to bring entries up to date, failed. Rebuild to try again. null when there's no fault. Starting a build clears it, and so does a refresh that finds the entries up to date.

    Show child attributes
    • messagestringrequired

      What went wrong, written to show to users.

    • atstring (date-time)required

      When the rebuild failed.

  • pendingSourcesobjectrequired

    The source changes waiting for POST .../apply: sources added that the knowledge base doesn't use yet, which sync meanwhile, sources removed that it uses until then, and files sources with a new file it doesn't use yet. Before the first build nothing waits, since the first build applies them.

    Show child attributes
    • addedintegerrequired

      How many sources were added to the knowledge base.

    • removedintegerrequired

      How many sources were removed from the knowledge base.

    • replacedintegerrequired

      How many files sources got a new file.

  • hasWebSourcebooleanrequired

    Whether the knowledge base has at least one website source.

  • webSourceLimitintegerrequired

    The maximum number of website sources the knowledge base can have. Adding one more returns 409 with code webSourceRootLimitExceeded.

  • hasDatasetSourcebooleanrequired

    Whether the knowledge base has at least one Sanity dataset source.

  • hasFileSourcebooleanrequired

    Whether the knowledge base has at least one uploaded file source.

  • sourceChunksintegerrequired

    The number of source chunks in the live documents of the knowledge base's sources, whether or not they have been built: the sum of its sources' chunkCount. It includes the chunks counted by excludedSourceChunks, and those of documents whose content another document repeats, which builds skip. Documents still being converted add theirs once converted.

  • excludedSourceChunksintegerrequired

    The number of source chunks in documents the organization's source chunk limit left out of builds. They count toward no limit, and the next build includes them once the limit has room.

  • Why a build request would be denied right now, or null if you can build. Only GET .../knowledge-bases/{knowledgeBaseId} checks it. List and create responses always return null.

    Show child attributes
    • codestringrequired

      A stable code for the restriction, such as planLimitReached.

    • messagestringrequired

      A readable explanation that you can show to users.

  • refreshInFlightbooleanrequired

    Whether a refresh is running now. While it's true, a new refresh request makes the running one run once more when it ends instead of starting another. Only GET .../knowledge-bases/{knowledgeBaseId} computes it, so list responses return false.

  • openIssueCountintegerrequired

    The number of open issues waiting for review. Always 0 before the first build.

  • instructionCountintegerrequired

    The number of active instructions for the knowledge base.

  • createdByrequired

    Who created the knowledge base. null if unknown.

    Show child attributes
    • idrequired

      The Sanity user ID, or sanity-system when Sanity Context made the change. null if unknown.

      Show child attributes
      • string
    • displayNamerequired

      The user's name when the action happened. null if unknown. For the current name, look up the user by id.

      Show child attributes
      • string
  • createdAtstring (date-time)required

    When the knowledge base was created.

  • updatedAtstring (date-time)required

    When the knowledge base was last updated.

Delete a knowledge base

delete/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}

Deletes the knowledge base and everything it owns: its sources, revisions, stored source files, and its documents in your organization's document store. The knowledge base is gone when the response returns. Its documents and stored files are removed in the background shortly after, so a query can still return them for a short time. While a build, refresh, apply, or sync is running, the request returns 409 with code buildInFlight. Retry after that work finishes. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Responses

204

The knowledge base was deleted.

Start a knowledge base build

post/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/build

Queues a build over the knowledge base's current sources and returns a job ID immediately. Follow its progress with GET .../jobs/{jobId}. If a build is already running, the response returns that build's job ID instead of starting a second build. A draft can't be built: the request returns 409 with code knowledgeBaseIsDraft. If the organization's other knowledge bases already use all the source chunks its plan allows, the request returns 403 with code planLimitReached. The knowledge base's buildRestriction shows this before you build. If background jobs are unavailable, the request returns 503 with code jobsUnavailable. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Header parameters

  • A unique value, such as a UUID, that makes retries safe. A retry with the same key and body returns the first response instead of repeating the work.

Responses

202

A queued job that you can poll for progress.

  • jobIdstringrequired

    The queued job's ID. Check its progress with GET .../jobs/{jobId}. Treat it as an opaque string. Its format can change.

Cancel a knowledge base build

post/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/build/cancel

Cancels the running build and resets the knowledge base so you can build it again. Returns cancelled: false when no build is running. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Responses

200

The result of the cancel request.

  • cancelledbooleanrequired

    Whether a running build was cancelled. false when no build was running.

sources

Add and sync the websites, Sanity datasets and files a knowledge base reads documents from.

List sources

get/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/sources

Lists the sources of a knowledge base: the websites, Sanity datasets and files its documents come from, each with its document counts and its latest sync. Results are cursor-paginated and sorted by source ID, not by when the sources were added. Requires read access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Query parameters

  • cursorstring

    The nextCursor value from the previous page. Omit it to get the first page.

  • limitintegerdefault: 50

    The maximum number of items to return.

Responses

200

A page of sources.

  • dataarrayrequired

    The items on this page.

    Show child attributes
    items
    • idstring (uuid)required

      The source's ID.

    • knowledgeBaseIdstringrequired

      The ID (kb…) of the knowledge base the source belongs to.

    • titlestringrequired

      The source's title.

    • documentCountintegerrequired

      The number of active and missing documents.

    • convertedDocumentCountintegerrequired

      How many of those documents are converted to markdown, ready for builds.

    • skippedDocumentCountintegerrequired

      How many of those documents have a file type that can't be converted.

    • failedDocumentCountintegerrequired

      How many of those documents failed to convert or were too large to.

    • chunkCountintegerrequired

      The number of chunks in its documents' markdown, the unit usage is counted in.

    • lastSyncedAtrequired

      When a sync of the source last finished. null before the first one.

      Show child attributes
      • string (date-time)
    • latestSyncrequired

      The most recent sync, running or finished. null before the first one.

      Show child attributes
      • idstring (uuid)required

        The sync's ID.

      • sourceIdstring (uuid)required

        The ID of the source the sync read.

      • modestringrequired

        full reads the whole source and removes what it no longer finds. incremental reads only what changed since the last sync.

      • triggerstringrequired

        What started the sync. schedule: the source's syncFrequency. manual: an API call or the dashboard, including the first sync of a website or dataset. upload: a file or text for a files source. event: a change to the documents of a sanity-dataset source whose syncFrequency is live. push is reserved and not set today.

      • statusstringrequired

        The sync's status. running: still reading or converting. completed, failed and cancelled are final.

      • documentsSeenintegerrequired

        The number of documents the sync read.

      • documentsUpsertedintegerrequired

        The number of documents the sync added or changed.

      • documentsUnchangedintegerrequired

        The number of documents the sync read that had not changed.

      • documentsDeletedintegerrequired

        The number of documents the sync deleted.

      • documentsMissingintegerrequired

        The number of web pages the sync marked missing because several crawls in a row didn't find them.

      • Why the sync stopped before it read the whole source, so it removed nothing. page-limit: the crawl reached its page limit. source-limit: the knowledge base had no room for more documents. stalled: the crawl stopped making progress. time-limit: the crawl ran out of time. null when the sync read the whole source, or hasn't finished.

        Show child attributes
        • string
          enum:"page-limit", "source-limit", "stalled", "time-limit"
      • errorrequired

        Why the sync failed, written to show to users. null unless status is failed.

        Show child attributes
        • string
      • createdAtstring (date-time)required

        When the sync started.

      • finishedAtrequired

        When the sync finished. null while it is running.

        Show child attributes
        • string (date-time)
    • pendingrequired

      A change to the knowledge base's sources that waits for POST .../apply. added: the source syncs, but the knowledge base doesn't use its documents until the change is applied. removed: the knowledge base uses its documents until the change is applied. replaced: a new file was uploaded to this files source, and the knowledge base uses the current one until the change is applied. replacementFailed: the new file's sync failed, was cancelled or never started; POST .../apply refuses until you sync the source again or discard the change, and the knowledge base keeps the current file. null: nothing waits.

      Show child attributes
      • string
        enum:"added", "removed", "replaced", "replacementFailed"
    • createdAtstring (date-time)required

      When the source was added.

    • updatedAtstring (date-time)required

      When the source last changed.

    • typestringrequired

      The source type. web is a crawled website.

    • urlstringrequired

      The URL the crawl starts from.

    • crawlOptionsobjectrequired

      Options that control how a website is crawled.

      Show child attributes
      • Regular expressions for URL paths to crawl. When set, the crawl only includes pages whose path matches one of them.

        Show child attributes
        items
        • string
      • Regular expressions for URL paths to skip. Pages whose path matches one of them aren't crawled.

        Show child attributes
        items
        • string
      • maxDepthinteger

        How many levels deep the crawl goes from the root URL.

      • Whether to crawl only the pages listed in the site's sitemap.

      • singlePageboolean

        Whether to add only the page at the URL, without crawling the pages under it. The other options are kept but don't apply while this is true.

      • Whether to treat URLs that differ only by query string as one page. New crawls set it to true unless you set it. Set it to false when the query string selects different content, such as pagination.

      • pageLimitinteger

        The maximum number of pages to crawl, up to 5,000. Defaults to 5,000. The crawl can stop sooner when the knowledge base reaches its source limit.

    • How often the source syncs on its own: weekly, monthly or live. live: a website is checked for changed pages every hour, and a dataset syncs soon after its documents change, plus a full sync once a day. null when it syncs only when asked to.

      Show child attributes
      • string
        enum:"weekly", "monthly", "live"
  • nextCursorrequired

    The cursor for the next page. Pass it as cursor to get more results. null when there are no more pages.

    Show child attributes
    • string

Add a source

post/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/sources

Adds a source to a knowledge base. Set type to choose what it reads:

  • web: a website, crawled from url
  • sanity-dataset: the documents a GROQ query selects in a Sanity dataset
  • files: files you upload with POST .../sources/{sourceId}/uploads, or text you send in content

A website or dataset starts its first sync right away. A files source syncs when you upload a file, or right away when you send content: one request stores the text, adds the source and starts its sync. A files source added without content is deleted when 24 hours pass with no sync and no new upload. For a website, set dryRun to true to preview the crawl without adding the source. To have a website or dataset sync on its own, set syncFrequency afterwards with PATCH .../sources/{sourceId}.

On a knowledge base that was built, the source syncs but the knowledge base doesn't use its documents, with pending set to added, until you call POST .../apply or send apply set to true.

A knowledge base can have up to 25 websites. Adding a website that is already a source returns 409 with code webSourceRootConflict, and adding one past the limit returns 409 with code webSourceRootLimitExceeded. When the preview can't be made, dryRun returns 502 with code crawlPreviewUnavailable. When the organization's knowledge bases already hold as many source chunks as its plan allows, the request returns 403 with code planLimitReached, with the plan's limit and the current usage in fields, and adds nothing.

Adding a dataset also requires full read access to the dataset and, on its project, the Administrator or Developer role or a custom role that can create datasets. Without the role, the request returns 403 with code projectAdminRequired, and without the read access, 403 with code datasetReadAccessDenied. A query that isn't valid GROQ returns 422 with code invalidGroqFilter, and a query that selects no published documents returns 422 with code datasetSourceEmpty. A dataset that is already a source of the knowledge base with a different query returns 409 with code datasetAlreadyBound; with the same query, the request returns the existing source.

Supports the Idempotency-Key header. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Header parameters

  • A unique value, such as a UUID, that makes retries safe. A retry with the same key and body returns the first response instead of repeating the work.

Request body application/json

  • typestringrequired

    The source type. web crawls a website.

  • urlstring (uri)required

    The page to add, or to start crawling from. It must be a public http or https URL.

  • Options for the crawl. Options you omit use the defaults.

    Show child attributes
    • Regular expressions for URL paths to crawl. When set, the crawl only includes pages whose path matches one of them.

      Show child attributes
      items
      • string
    • Regular expressions for URL paths to skip. Pages whose path matches one of them aren't crawled.

      Show child attributes
      items
      • string
    • maxDepthinteger

      How many levels deep the crawl goes from the root URL.

    • Whether to crawl only the pages listed in the site's sitemap.

    • singlePageboolean

      Whether to add only the page at the URL, without crawling the pages under it. The other options are kept but don't apply while this is true.

    • Whether to treat URLs that differ only by query string as one page. New crawls set it to true unless you set it. Set it to false when the query string selects different content, such as pagination.

    • pageLimitinteger

      The maximum number of pages to crawl, up to 5,000. Defaults to 5,000. The crawl can stop sooner when the knowledge base reaches its source limit.

  • dryRunboolean

    Set to true to estimate what a crawl would fetch without adding the source. The response is then 200 with a preview of the pages the site has, grouped by path. The preview leaves out pages that the include and exclude patterns in crawlOptions rule out.

  • applyboolean

    Set to true to have the knowledge base use the source at once instead of waiting for POST .../apply. A knowledge base that was never built uses a new source at once anyway, since its first build applies it.

Responses

200

The preview of a crawl, when dryRun is true.

  • totalPagesintegerrequired

    How many pages the crawl would fetch, roughly. It includes the page at the URL unless the include and exclude patterns rule it out.

  • foundPagesintegerrequired

    Roughly how many pages exist at and under the URL, before the include and exclude patterns. Equal to totalPages when there are no patterns.

  • truncatedbooleanrequired

    Whether the site has more pages than the preview counted.

  • groupsarrayrequired

    The largest groups of pages by path, largest first.

    Show child attributes
    items
    • prefixstringrequired

      The path the pages in the group share, such as /docs/.

    • countintegerrequired

      How many pages the group has.

  • otherCountintegerrequired

    How many of the pages the map listed are outside groups.

  • pagesarrayrequired

    The pages totalPages counts, as full URLs sorted by path. The page at the URL comes first when it is included. At most 500: with more, the first 250 and the last 250.

    Show child attributes
    items
    • string

Get a source

get/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/sources/{sourceId}

Returns a source with its settings, document counts and latest sync. A source the knowledge base doesn't have returns 404 with code sourceNotFound. Requires read access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • sourceIdstring (uuid)required

    The source's ID.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Responses

200

The source.

  • idstring (uuid)required

    The source's ID.

  • knowledgeBaseIdstringrequired

    The ID (kb…) of the knowledge base the source belongs to.

  • titlestringrequired

    The source's title.

  • documentCountintegerrequired

    The number of active and missing documents.

  • convertedDocumentCountintegerrequired

    How many of those documents are converted to markdown, ready for builds.

  • skippedDocumentCountintegerrequired

    How many of those documents have a file type that can't be converted.

  • failedDocumentCountintegerrequired

    How many of those documents failed to convert or were too large to.

  • chunkCountintegerrequired

    The number of chunks in its documents' markdown, the unit usage is counted in.

  • lastSyncedAtrequired

    When a sync of the source last finished. null before the first one.

    Show child attributes
    • string (date-time)
  • latestSyncrequired

    The most recent sync, running or finished. null before the first one.

    Show child attributes
    • idstring (uuid)required

      The sync's ID.

    • sourceIdstring (uuid)required

      The ID of the source the sync read.

    • modestringrequired

      full reads the whole source and removes what it no longer finds. incremental reads only what changed since the last sync.

    • triggerstringrequired

      What started the sync. schedule: the source's syncFrequency. manual: an API call or the dashboard, including the first sync of a website or dataset. upload: a file or text for a files source. event: a change to the documents of a sanity-dataset source whose syncFrequency is live. push is reserved and not set today.

    • statusstringrequired

      The sync's status. running: still reading or converting. completed, failed and cancelled are final.

    • documentsSeenintegerrequired

      The number of documents the sync read.

    • documentsUpsertedintegerrequired

      The number of documents the sync added or changed.

    • documentsUnchangedintegerrequired

      The number of documents the sync read that had not changed.

    • documentsDeletedintegerrequired

      The number of documents the sync deleted.

    • documentsMissingintegerrequired

      The number of web pages the sync marked missing because several crawls in a row didn't find them.

    • Why the sync stopped before it read the whole source, so it removed nothing. page-limit: the crawl reached its page limit. source-limit: the knowledge base had no room for more documents. stalled: the crawl stopped making progress. time-limit: the crawl ran out of time. null when the sync read the whole source, or hasn't finished.

      Show child attributes
      • string
        enum:"page-limit", "source-limit", "stalled", "time-limit"
    • errorrequired

      Why the sync failed, written to show to users. null unless status is failed.

      Show child attributes
      • string
    • createdAtstring (date-time)required

      When the sync started.

    • finishedAtrequired

      When the sync finished. null while it is running.

      Show child attributes
      • string (date-time)
  • pendingrequired

    A change to the knowledge base's sources that waits for POST .../apply. added: the source syncs, but the knowledge base doesn't use its documents until the change is applied. removed: the knowledge base uses its documents until the change is applied. replaced: a new file was uploaded to this files source, and the knowledge base uses the current one until the change is applied. replacementFailed: the new file's sync failed, was cancelled or never started; POST .../apply refuses until you sync the source again or discard the change, and the knowledge base keeps the current file. null: nothing waits.

    Show child attributes
    • string
      enum:"added", "removed", "replaced", "replacementFailed"
  • createdAtstring (date-time)required

    When the source was added.

  • updatedAtstring (date-time)required

    When the source last changed.

  • typestringrequired

    The source type. web is a crawled website.

  • urlstringrequired

    The URL the crawl starts from.

  • crawlOptionsobjectrequired

    Options that control how a website is crawled.

    Show child attributes
    • Regular expressions for URL paths to crawl. When set, the crawl only includes pages whose path matches one of them.

      Show child attributes
      items
      • string
    • Regular expressions for URL paths to skip. Pages whose path matches one of them aren't crawled.

      Show child attributes
      items
      • string
    • maxDepthinteger

      How many levels deep the crawl goes from the root URL.

    • Whether to crawl only the pages listed in the site's sitemap.

    • singlePageboolean

      Whether to add only the page at the URL, without crawling the pages under it. The other options are kept but don't apply while this is true.

    • Whether to treat URLs that differ only by query string as one page. New crawls set it to true unless you set it. Set it to false when the query string selects different content, such as pagination.

    • pageLimitinteger

      The maximum number of pages to crawl, up to 5,000. Defaults to 5,000. The crawl can stop sooner when the knowledge base reaches its source limit.

  • How often the source syncs on its own: weekly, monthly or live. live: a website is checked for changed pages every hour, and a dataset syncs soon after its documents change, plus a full sync once a day. null when it syncs only when asked to.

    Show child attributes
    • string
      enum:"weekly", "monthly", "live"

Update a source

patch/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/sources/{sourceId}

Changes a source's title, a website's crawl options, a dataset's query, or how often a website or dataset syncs on its own. New crawl options replace the stored ones, except that an omitted ignoreQueryParameters keeps its current value. They delete the documents whose path they leave out, and pages they let in are fetched by the next sync: start one with POST .../sources/{sourceId}/syncs to fetch them now. New crawl options sent while the source syncs return 409 with code syncInProgress; send them again once the sync finishes. A new query queues a sync, which removes the documents the query no longer selects.

Crawl options on a source that isn't a website, a query on one that isn't a dataset, or a sync frequency on a files source, return 422 with code sourceTypeMismatch. Setting a sync frequency on a plan without scheduled syncs returns 403 with code featureNotInPlan; setting it to null always works. A source the knowledge base doesn't have returns 404 with code sourceNotFound.

A new query also requires full read access to the dataset and, on its project, the Administrator or Developer role or a custom role that can create datasets. Without the role, the request returns 403 with code projectAdminRequired, and without the read access, 403 with code datasetReadAccessDenied. A query that isn't valid GROQ returns 422 with code invalidGroqFilter, and a query that selects no published documents returns 422 with code datasetSourceEmpty.

Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • sourceIdstring (uuid)required

    The source's ID.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Request body application/json

  • titlestring

    The source's title.

  • For a web source, the crawl options, replacing the stored ones. An omitted ignoreQueryParameters keeps its current value. Documents whose path the new include and exclude paths leave out are deleted, and pages they newly let in are fetched by the next sync.

    Show child attributes
    • Regular expressions for URL paths to crawl. When set, the crawl only includes pages whose path matches one of them.

      Show child attributes
      items
      • string
    • Regular expressions for URL paths to skip. Pages whose path matches one of them aren't crawled.

      Show child attributes
      items
      • string
    • maxDepthinteger

      How many levels deep the crawl goes from the root URL.

    • Whether to crawl only the pages listed in the site's sitemap.

    • singlePageboolean

      Whether to add only the page at the URL, without crawling the pages under it. The other options are kept but don't apply while this is true.

    • Whether to treat URLs that differ only by query string as one page. New crawls set it to true unless you set it. Set it to false when the query string selects different content, such as pagination.

    • pageLimitinteger

      The maximum number of pages to crawl, up to 5,000. Defaults to 5,000. The crawl can stop sooner when the knowledge base reaches its source limit.

  • querystring

    For a sanity-dataset source, the GROQ query, replacing the stored one. A sync is queued, and removes the documents the query no longer returns.

  • For a web or sanity-dataset source, how often it syncs on its own: weekly, monthly or live. live: a website is checked for changed pages every hour, and a dataset syncs soon after its documents change, plus a full sync once a day. null stops scheduled syncs, and you can still start a sync yourself. Setting a frequency requires a plan that includes scheduled syncs; without one, the request returns 403 with code featureNotInPlan.

    Show child attributes
    • string
      enum:"weekly", "monthly", "live"

Responses

200

The source with the changes made.

  • idstring (uuid)required

    The source's ID.

  • knowledgeBaseIdstringrequired

    The ID (kb…) of the knowledge base the source belongs to.

  • titlestringrequired

    The source's title.

  • documentCountintegerrequired

    The number of active and missing documents.

  • convertedDocumentCountintegerrequired

    How many of those documents are converted to markdown, ready for builds.

  • skippedDocumentCountintegerrequired

    How many of those documents have a file type that can't be converted.

  • failedDocumentCountintegerrequired

    How many of those documents failed to convert or were too large to.

  • chunkCountintegerrequired

    The number of chunks in its documents' markdown, the unit usage is counted in.

  • lastSyncedAtrequired

    When a sync of the source last finished. null before the first one.

    Show child attributes
    • string (date-time)
  • latestSyncrequired

    The most recent sync, running or finished. null before the first one.

    Show child attributes
    • idstring (uuid)required

      The sync's ID.

    • sourceIdstring (uuid)required

      The ID of the source the sync read.

    • modestringrequired

      full reads the whole source and removes what it no longer finds. incremental reads only what changed since the last sync.

    • triggerstringrequired

      What started the sync. schedule: the source's syncFrequency. manual: an API call or the dashboard, including the first sync of a website or dataset. upload: a file or text for a files source. event: a change to the documents of a sanity-dataset source whose syncFrequency is live. push is reserved and not set today.

    • statusstringrequired

      The sync's status. running: still reading or converting. completed, failed and cancelled are final.

    • documentsSeenintegerrequired

      The number of documents the sync read.

    • documentsUpsertedintegerrequired

      The number of documents the sync added or changed.

    • documentsUnchangedintegerrequired

      The number of documents the sync read that had not changed.

    • documentsDeletedintegerrequired

      The number of documents the sync deleted.

    • documentsMissingintegerrequired

      The number of web pages the sync marked missing because several crawls in a row didn't find them.

    • Why the sync stopped before it read the whole source, so it removed nothing. page-limit: the crawl reached its page limit. source-limit: the knowledge base had no room for more documents. stalled: the crawl stopped making progress. time-limit: the crawl ran out of time. null when the sync read the whole source, or hasn't finished.

      Show child attributes
      • string
        enum:"page-limit", "source-limit", "stalled", "time-limit"
    • errorrequired

      Why the sync failed, written to show to users. null unless status is failed.

      Show child attributes
      • string
    • createdAtstring (date-time)required

      When the sync started.

    • finishedAtrequired

      When the sync finished. null while it is running.

      Show child attributes
      • string (date-time)
  • pendingrequired

    A change to the knowledge base's sources that waits for POST .../apply. added: the source syncs, but the knowledge base doesn't use its documents until the change is applied. removed: the knowledge base uses its documents until the change is applied. replaced: a new file was uploaded to this files source, and the knowledge base uses the current one until the change is applied. replacementFailed: the new file's sync failed, was cancelled or never started; POST .../apply refuses until you sync the source again or discard the change, and the knowledge base keeps the current file. null: nothing waits.

    Show child attributes
    • string
      enum:"added", "removed", "replaced", "replacementFailed"
  • createdAtstring (date-time)required

    When the source was added.

  • updatedAtstring (date-time)required

    When the source last changed.

  • typestringrequired

    The source type. web is a crawled website.

  • urlstringrequired

    The URL the crawl starts from.

  • crawlOptionsobjectrequired

    Options that control how a website is crawled.

    Show child attributes
    • Regular expressions for URL paths to crawl. When set, the crawl only includes pages whose path matches one of them.

      Show child attributes
      items
      • string
    • Regular expressions for URL paths to skip. Pages whose path matches one of them aren't crawled.

      Show child attributes
      items
      • string
    • maxDepthinteger

      How many levels deep the crawl goes from the root URL.

    • Whether to crawl only the pages listed in the site's sitemap.

    • singlePageboolean

      Whether to add only the page at the URL, without crawling the pages under it. The other options are kept but don't apply while this is true.

    • Whether to treat URLs that differ only by query string as one page. New crawls set it to true unless you set it. Set it to false when the query string selects different content, such as pagination.

    • pageLimitinteger

      The maximum number of pages to crawl, up to 5,000. Defaults to 5,000. The crawl can stop sooner when the knowledge base reaches its source limit.

  • How often the source syncs on its own: weekly, monthly or live. live: a website is checked for changed pages every hour, and a dataset syncs soon after its documents change, plus a full sync once a day. null when it syncs only when asked to.

    Show child attributes
    • string
      enum:"weekly", "monthly", "live"

Delete a source

delete/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/sources/{sourceId}

Removes a source and its documents from the knowledge base. On a knowledge base that was built, the knowledge base keeps using the source, with pending set to removed, until you call POST .../apply or send apply set to true. A source the knowledge base doesn't use yet is removed at once.

Removing a source the knowledge base uses starts a refresh that removes the citations of its documents from entries and deletes the entries left with none. The source stops syncing and is deleted once that refresh has run. A source the knowledge base doesn't have returns 404 with code sourceNotFound.

Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • sourceIdstring (uuid)required

    The source's ID.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Query parameters

  • applystring

    Set to true to remove the source at once instead of waiting for POST .../apply.

Responses

204

The source was removed, or marked to be removed.

List a source's syncs

get/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/sources/{sourceId}/syncs

Lists the syncs of a source, newest first. Results are cursor-paginated. A source the knowledge base doesn't have returns 404 with code sourceNotFound. Requires read access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • sourceIdstring (uuid)required

    The source's ID.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Query parameters

  • cursorstring

    The nextCursor value from the previous page. Omit it to get the first page.

  • limitintegerdefault: 50

    The maximum number of items to return.

Responses

200

A page of syncs.

  • dataarrayrequired

    The items on this page.

    Show child attributes
    items
    • idstring (uuid)required

      The sync's ID.

    • sourceIdstring (uuid)required

      The ID of the source the sync read.

    • modestringrequired

      full reads the whole source and removes what it no longer finds. incremental reads only what changed since the last sync.

    • triggerstringrequired

      What started the sync. schedule: the source's syncFrequency. manual: an API call or the dashboard, including the first sync of a website or dataset. upload: a file or text for a files source. event: a change to the documents of a sanity-dataset source whose syncFrequency is live. push is reserved and not set today.

    • statusstringrequired

      The sync's status. running: still reading or converting. completed, failed and cancelled are final.

    • documentsSeenintegerrequired

      The number of documents the sync read.

    • documentsUpsertedintegerrequired

      The number of documents the sync added or changed.

    • documentsUnchangedintegerrequired

      The number of documents the sync read that had not changed.

    • documentsDeletedintegerrequired

      The number of documents the sync deleted.

    • documentsMissingintegerrequired

      The number of web pages the sync marked missing because several crawls in a row didn't find them.

    • Why the sync stopped before it read the whole source, so it removed nothing. page-limit: the crawl reached its page limit. source-limit: the knowledge base had no room for more documents. stalled: the crawl stopped making progress. time-limit: the crawl ran out of time. null when the sync read the whole source, or hasn't finished.

      Show child attributes
      • string
        enum:"page-limit", "source-limit", "stalled", "time-limit"
    • errorrequired

      Why the sync failed, written to show to users. null unless status is failed.

      Show child attributes
      • string
    • createdAtstring (date-time)required

      When the sync started.

    • finishedAtrequired

      When the sync finished. null while it is running.

      Show child attributes
      • string (date-time)
  • nextCursorrequired

    The cursor for the next page. Pass it as cursor to get more results. null when there are no more pages.

    Show child attributes
    • string

Sync a source

post/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/sources/{sourceId}/syncs

Starts a sync of the source. A website or dataset is read again: its sync is queued, and starts once any sync of the source that is running ends, including the first one that started when it was added. Asking again while one waits queues nothing more. The response has no job ID for it: follow it with the source's latestSync. Until the queued sync starts, latestSync still shows the previous one, so compare its createdAt with the time of your request.

For a files source, set uploadId to the upload whose file the source should hold from now on; without it, the source reads its current file again. Its sync starts at once and returns a job ID to poll; the finished job's result names the sync. While a sync of a files source is running, including the first one, the request returns 409 with code syncInProgress and leaves the upload for a later request. An uploadId whose file never arrived returns 404 with code uploadNotFound, and so does a request without uploadId on a files source that has no file yet, with fields.uploadId set to null. A file larger than 5 GB returns 413 with code uploadTooLarge. An uploadId on a source that isn't files returns 422 with code sourceTypeMismatch, and a source the knowledge base doesn't have returns 404 with code sourceNotFound.

When the knowledge base is built and already uses the source, the new file waits for POST .../apply: the sync reads and converts it, but the knowledge base keeps using the current file until then, and the source's pending is replaced. Set apply to true to use the new file at once. A new upload while one waits replaces the waiting one, and POST .../discard drops it.

Supports the Idempotency-Key header. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • sourceIdstring (uuid)required

    The source's ID.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Header parameters

  • A unique value, such as a UUID, that makes retries safe. A retry with the same key and body returns the first response instead of repeating the work.

Request body application/json

  • uploadIdstring (uuid)

    For a files source, the uploadId of the file to sync, from POST .../sources/{sourceId}/uploads. Without it, a files source reads its current file again. Not allowed for other types.

  • applyboolean

    With uploadId, set to true to have the knowledge base use the new file at once instead of waiting for POST .../apply. A knowledge base that was never built, or a source it doesn't use yet, uses the new file at once anyway.

Responses

202

The sync that was started or queued.

  • sourceIdstring (uuid)required

    The ID of the source that will sync.

  • jobIdrequired

    For a files source, the ID of the sync's job. Check its progress with GET .../jobs/{jobId}; once it succeeds, its result names the sync. null for a website or dataset, whose sync is queued on the source: follow it with the source's latestSync.

    Show child attributes
    • string

Get a sync

get/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/sources/{sourceId}/syncs/{syncId}

Returns one sync of a source with its status and counts. A source the knowledge base doesn't have returns 404 with code sourceNotFound, and a sync the source doesn't have returns 404 with code syncNotFound. Requires read access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • sourceIdstring (uuid)required

    The source's ID.

  • syncIdstring (uuid)required

    The sync's ID.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Responses

200

The sync.

  • idstring (uuid)required

    The sync's ID.

  • sourceIdstring (uuid)required

    The ID of the source the sync read.

  • modestringrequired

    full reads the whole source and removes what it no longer finds. incremental reads only what changed since the last sync.

  • triggerstringrequired

    What started the sync. schedule: the source's syncFrequency. manual: an API call or the dashboard, including the first sync of a website or dataset. upload: a file or text for a files source. event: a change to the documents of a sanity-dataset source whose syncFrequency is live. push is reserved and not set today.

  • statusstringrequired

    The sync's status. running: still reading or converting. completed, failed and cancelled are final.

  • documentsSeenintegerrequired

    The number of documents the sync read.

  • documentsUpsertedintegerrequired

    The number of documents the sync added or changed.

  • documentsUnchangedintegerrequired

    The number of documents the sync read that had not changed.

  • documentsDeletedintegerrequired

    The number of documents the sync deleted.

  • documentsMissingintegerrequired

    The number of web pages the sync marked missing because several crawls in a row didn't find them.

  • Why the sync stopped before it read the whole source, so it removed nothing. page-limit: the crawl reached its page limit. source-limit: the knowledge base had no room for more documents. stalled: the crawl stopped making progress. time-limit: the crawl ran out of time. null when the sync read the whole source, or hasn't finished.

    Show child attributes
    • string
      enum:"page-limit", "source-limit", "stalled", "time-limit"
  • errorrequired

    Why the sync failed, written to show to users. null unless status is failed.

    Show child attributes
    • string
  • createdAtstring (date-time)required

    When the sync started.

  • finishedAtrequired

    When the sync finished. null while it is running.

    Show child attributes
    • string (date-time)

Upload a file to a source

post/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/sources/{sourceId}/uploads

Returns a signed URL for one file of a files source, valid for one hour. To add the file:

  1. Send the file as the body of a PUT request to uploadUrl. If you set contentType, send the same Content-Type header. Sending to the URL again replaces the file.
  2. Call POST .../sources/{sourceId}/syncs with the uploadId.

The file replaces the source's current file when it syncs. An upload no sync takes within 24 hours is deleted.

The file can be up to 5 GB. It can be a single document or a zip, tar or gzip archive of them. An archive can unpack to 200 times its size, at least 1 GB and at most 20 GB; a larger one fails its sync. A file over 1 GB, alone or in an archive, is listed as a document with conversion set to oversized, and isn't read. The format of each file is detected from its contents and its name. PDF, Word, Excel, PowerPoint, OpenDocument, EPUB, RTF, HTML and image files are converted to markdown up to 50 MB each. Markdown, text, code and data files such as JSON, CSV and YAML are read as they are. A file in any other format becomes a short markdown summary of its name, media type and size.

A source that isn't files returns 422 with code sourceTypeMismatch, and a source the knowledge base doesn't have returns 404 with code sourceNotFound. When the organization's knowledge bases already hold as many source chunks as its plan allows, the request returns 403 with code planLimitReached. Supports the Idempotency-Key header. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • sourceIdstring (uuid)required

    The source's ID.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Header parameters

  • A unique value, such as a UUID, that makes retries safe. A retry with the same key and body returns the first response instead of repeating the work.

Request body application/json

  • filenamestringrequired

    The file's name.

  • The media type of the file. When set, the PUT request must send the same Content-Type header.

Responses

201

Where to upload the file.

  • uploadIdstring (uuid)required

    The ID of the upload. Pass it to POST .../syncs once the file is uploaded.

  • uploadUrlstring (uri)required

    A signed URL to send the file to in one PUT request. It expires after one hour.

Sync every source

post/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/sync

Queues a sync of every website and dataset source, which starts once any sync of the source that is running ends. files sources sync when you upload a file. New documents from these syncs, and new documents still waiting from earlier syncs, go into the knowledge base's entries as soon as they are ready instead of after the usual wait. Many new documents can take more than one update to go in. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Responses

202

The syncs that were queued.

  • sourceIdsarrayrequired

    The IDs of the sources that will sync. Follow each with the source's latestSync. files sources aren't included: they sync when you upload a file.

    Show child attributes
    items
    • string (uuid)

Apply source changes

post/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/apply

Queues a job that applies the sources added to or removed from a built knowledge base, and the new files uploaded to its files sources, and returns its job ID. Until then, an added source syncs but the knowledge base doesn't use its documents, a removed source stays in use, and a source with a new file keeps its current one. Each source shows what waits in pending, and the knowledge base counts it in pendingSources.

The job takes the added sources' documents into the knowledge base, and removes the citations of the removed sources' documents from entries, deleting the entries left with none. A new file replaces the current one, and the knowledge base updates the entries that cite it. Its result counts the sources it applied; with nothing waiting it changes nothing. An apply asked for while the knowledge base is building or updating starts when that work ends. Changes inside a source the knowledge base already uses, such as pages a sync finds edited, need no apply.

While an added source's sync runs, or while an added source that never synced waits for its first sync to start (a files source still waiting for its first file doesn't count), or while a new file's sync runs or is about to start, the request returns 409 with code sourcesSyncing and fields.sourceIds naming those sources, and applies nothing. Send it again once they finish. A new file whose sync failed, was cancelled or never started isn't applied and keeps waiting, with pending set to replacementFailed: upload it again, or discard the change with POST .../discard. A new file on a source whose removal also waits isn't applied: the removal is.

Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Responses

202

A queued job that you can poll for progress.

  • jobIdstringrequired

    The queued job's ID. Check its progress with GET .../jobs/{jobId}. Treat it as an opaque string. Its format can change.

Discard source changes

post/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/discard

Drops the source changes waiting for POST .../apply, at once. Added sources are removed from the knowledge base and deleted with their documents. Removed sources stay, and their pending goes back to null. A new file waiting on a source is dropped and the source keeps its current one. While the sync of a new file runs or is about to start, the request returns 409 with code sourcesSyncing and fields.sourceIds naming those sources, and discards nothing. Returns the counts of what was discarded; with nothing waiting it changes nothing. An apply already queued finds nothing left to apply. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Responses

200

The source changes that waited for POST .../apply and were discarded: added sources now removed from the knowledge base, removals the knowledge base now keeps, and new files dropped.

  • addedintegerrequired

    How many sources were added to the knowledge base.

  • removedintegerrequired

    How many sources were removed from the knowledge base.

  • replacedintegerrequired

    How many files sources got a new file.

documents

Read and remove the documents sources yield, which builds read and cite.

List documents

get/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/documents

Lists the documents in a knowledge base: the pages, dataset documents and files its sources yield, which builds read and cite. Results are cursor-paginated, and you can filter them by source and state. Requires read access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Query parameters

  • cursorstring

    The nextCursor value from the previous page. Omit it to get the first page.

  • limitintegerdefault: 50

    The maximum number of items to return.

  • sourcestring (uuid)

    Return only the documents of this source.

  • statestring

    Return only documents in this state. Without it, deleted documents are left out.

  • idsstring

    Comma-separated IDs of the documents to return, up to 200, in any state. IDs that match no document are left out. The results are still paginated, so set limit to at least the number of IDs to get them in one page. Use it to look up the documents entry citations point at.

Responses

200

A page of documents.

  • dataarrayrequired

    The items on this page.

    Show child attributes
    items
    • idstring (uuid)required

      The document's ID. Entry citations point at it.

    • sourceIdstring (uuid)required

      The ID of the source the document comes from.

    • sourceTypestringrequired

      The type of the source the document comes from.

    • externalIdstringrequired

      The document's identity in its source: the page URL, the dataset document _id, or the file's path in the upload.

    • titlestringrequired

      The document's title, or its externalId when it has none.

    • urlrequired

      Where the document lives on the web. null for files and dataset documents.

      Show child attributes
      • string
    • statestringrequired

      The document's state. active: in the knowledge base. missing: several crawls in a row didn't find the page, but it stays in the knowledge base until you delete or keep it. deleted: removed from the source, or by you.

    • mimerequired

      The media type of the document as read. null before its content was read.

      Show child attributes
      • string
    • sizeBytesrequired

      The size of the document as read, in bytes. null before its content was read.

      Show child attributes
      • integer
    • conversionstringrequired

      How far the current content got through conversion to markdown, the text builds read and cite. pending: not converted yet. converted: ready. unsupported: the file type has no converter. oversized: too large to convert. failed: conversion failed, see conversionError.

    • Why conversion failed. null unless conversion is failed or oversized.

      Show child attributes
      • string
    • truncationrequired

      Set when the document is longer than the most pages conversion reads from one file (5,000), so only its first pagesRead pages are in the knowledge base. To include the rest, split the file into parts of at most 5,000 pages and upload those. null when every page was converted.

      Show child attributes
      • pagesReadintegerrequired

        How many pages were converted, from the first.

      • totalPagesintegerrequired

        How many pages the document has.

    • excludedAtrequired

      When a build left the document out because the organization's source chunk limit had no room for it. No build reads it until a later build finds room, which includes it automatically. null while builds include it.

      Show child attributes
      • string (date-time)
    • When the document says it was last updated: from a page's meta tags, a file's own metadata, or a dataset document's _updatedAt. null when it doesn't say.

      Show child attributes
      • string (date-time)
    • lastSeenAtstring (date-time)required

      When a sync last found the document in its source.

    • createdAtstring (date-time)required

      When the document was first read.

    • updatedAtstring (date-time)required

      When the document last changed.

  • nextCursorrequired

    The cursor for the next page. Pass it as cursor to get more results. null when there are no more pages.

    Show child attributes
    • string

Get a document

get/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/documents/{documentId}

Returns a document with its conversion status and the chunks of its markdown. Entry citations point at a document's chunks. A document the knowledge base doesn't have returns 404 with code documentNotFound. Requires read access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • documentIdstring (uuid)required

    The document's ID.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Responses

200

A document with the chunks of its markdown.

  • idstring (uuid)required

    The document's ID. Entry citations point at it.

  • sourceIdstring (uuid)required

    The ID of the source the document comes from.

  • sourceTypestringrequired

    The type of the source the document comes from.

  • externalIdstringrequired

    The document's identity in its source: the page URL, the dataset document _id, or the file's path in the upload.

  • titlestringrequired

    The document's title, or its externalId when it has none.

  • urlrequired

    Where the document lives on the web. null for files and dataset documents.

    Show child attributes
    • string
  • statestringrequired

    The document's state. active: in the knowledge base. missing: several crawls in a row didn't find the page, but it stays in the knowledge base until you delete or keep it. deleted: removed from the source, or by you.

  • mimerequired

    The media type of the document as read. null before its content was read.

    Show child attributes
    • string
  • sizeBytesrequired

    The size of the document as read, in bytes. null before its content was read.

    Show child attributes
    • integer
  • conversionstringrequired

    How far the current content got through conversion to markdown, the text builds read and cite. pending: not converted yet. converted: ready. unsupported: the file type has no converter. oversized: too large to convert. failed: conversion failed, see conversionError.

  • Why conversion failed. null unless conversion is failed or oversized.

    Show child attributes
    • string
  • truncationrequired

    Set when the document is longer than the most pages conversion reads from one file (5,000), so only its first pagesRead pages are in the knowledge base. To include the rest, split the file into parts of at most 5,000 pages and upload those. null when every page was converted.

    Show child attributes
    • pagesReadintegerrequired

      How many pages were converted, from the first.

    • totalPagesintegerrequired

      How many pages the document has.

  • excludedAtrequired

    When a build left the document out because the organization's source chunk limit had no room for it. No build reads it until a later build finds room, which includes it automatically. null while builds include it.

    Show child attributes
    • string (date-time)
  • When the document says it was last updated: from a page's meta tags, a file's own metadata, or a dataset document's _updatedAt. null when it doesn't say.

    Show child attributes
    • string (date-time)
  • lastSeenAtstring (date-time)required

    When a sync last found the document in its source.

  • createdAtstring (date-time)required

    When the document was first read.

  • updatedAtstring (date-time)required

    When the document last changed.

  • chunksarrayrequired

    The chunks of the document's current markdown, in order. Empty until conversion is converted.

    Show child attributes
    items
    • idstring (uuid)required

      The chunk's ID. Entry citations point at it.

    • headingPatharrayrequired

      The headings above the chunk, outermost first. Empty before the first heading.

      Show child attributes
      items
      • string
    • lineStartintegerrequired

      The chunk's first line in the markdown, from 1.

    • lineEndintegerrequired

      The chunk's last line in the markdown, inclusive.

Keep a missing document

patch/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/documents/{documentId}

Keeps a missing web page in the knowledge base by setting its state back to active. A document that isn't missing returns 409 with code documentInvalidState, and a document the knowledge base doesn't have returns 404 with code documentNotFound. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • documentIdstring (uuid)required

    The document's ID.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Request body application/json

  • statestringrequired

    Set to active to keep a missing page in the knowledge base. The count of crawls that missed it starts again.

Responses

200

The document, now active.

  • idstring (uuid)required

    The document's ID. Entry citations point at it.

  • sourceIdstring (uuid)required

    The ID of the source the document comes from.

  • sourceTypestringrequired

    The type of the source the document comes from.

  • externalIdstringrequired

    The document's identity in its source: the page URL, the dataset document _id, or the file's path in the upload.

  • titlestringrequired

    The document's title, or its externalId when it has none.

  • urlrequired

    Where the document lives on the web. null for files and dataset documents.

    Show child attributes
    • string
  • statestringrequired

    The document's state. active: in the knowledge base. missing: several crawls in a row didn't find the page, but it stays in the knowledge base until you delete or keep it. deleted: removed from the source, or by you.

  • mimerequired

    The media type of the document as read. null before its content was read.

    Show child attributes
    • string
  • sizeBytesrequired

    The size of the document as read, in bytes. null before its content was read.

    Show child attributes
    • integer
  • conversionstringrequired

    How far the current content got through conversion to markdown, the text builds read and cite. pending: not converted yet. converted: ready. unsupported: the file type has no converter. oversized: too large to convert. failed: conversion failed, see conversionError.

  • Why conversion failed. null unless conversion is failed or oversized.

    Show child attributes
    • string
  • truncationrequired

    Set when the document is longer than the most pages conversion reads from one file (5,000), so only its first pagesRead pages are in the knowledge base. To include the rest, split the file into parts of at most 5,000 pages and upload those. null when every page was converted.

    Show child attributes
    • pagesReadintegerrequired

      How many pages were converted, from the first.

    • totalPagesintegerrequired

      How many pages the document has.

  • excludedAtrequired

    When a build left the document out because the organization's source chunk limit had no room for it. No build reads it until a later build finds room, which includes it automatically. null while builds include it.

    Show child attributes
    • string (date-time)
  • When the document says it was last updated: from a page's meta tags, a file's own metadata, or a dataset document's _updatedAt. null when it doesn't say.

    Show child attributes
    • string (date-time)
  • lastSeenAtstring (date-time)required

    When a sync last found the document in its source.

  • createdAtstring (date-time)required

    When the document was first read.

  • updatedAtstring (date-time)required

    When the document last changed.

Delete a document

delete/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/documents/{documentId}

Deletes a document from its source. The document stays listed with state set to deleted, and deleting it again returns 204. A page that is still on the website comes back on the next sync of its source unless the crawl options exclude it. Entries that cite the document stay the same until the next build or refresh, which removes the citations. A document the knowledge base doesn't have returns 404 with code documentNotFound. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • documentIdstring (uuid)required

    The document's ID.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Responses

204

The document was deleted.

Get a document's markdown

get/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/documents/{documentId}/content

Returns the markdown a document converted to: the text builds read, and the line numbers citations use. Set chunk or lines to get part of it, and format to markdown or plain to get the text alone instead of JSON. Setting both chunk and lines, or either one with format=raw, returns 400 with code validationError. Until the document is converted, the request returns 409 with code documentNotConverted. A document the knowledge base doesn't have returns 404 with code documentNotFound, and a chunk the document doesn't have returns 404 with code chunkNotFound. Chunk IDs follow the document's headings, so a chunk a citation names can be gone once the document changes. With format=raw it returns the document as its source gave it, as a file download: the body has the document's media type, and the Content-Disposition header names the file. A web page downloads as a .md file and a dataset document as a .json file. When the document was too large to keep, format=raw returns 409 with code documentNotStored. Requires read access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • documentIdstring (uuid)required

    The document's ID.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Query parameters

  • formatstring

    Response format. json (default) returns the markdown with its line numbers. markdown and plain return the markdown alone, ready to pass to a model. raw returns the document as its source gave it, before conversion: an uploaded file as it was uploaded, a web page as the markdown the crawl read from it, and a dataset document as JSON.

  • chunkstring (uuid)

    Return only this chunk's lines. Citations name the chunk they quote.

  • linesstring

    Return only these lines, from 1 and inclusive: 10-20, or 10 for line 10 to the end. A range past the end returns up to the last line.

Responses

200

A document's markdown, or a range of its lines.

  • documentIdstring (uuid)required

    The document's ID.

  • chunkIdrequired

    The chunk the content was limited to. null when no chunk was requested.

    Show child attributes
    • string (uuid)
  • contentstringrequired

    The document's markdown, or the requested lines of it.

  • totalLinesintegerrequired

    The number of lines in the whole markdown.

  • sliceobjectrequired

    The lines returned, from 1 and inclusive. Shorter than requested when the range runs past the end. Both are 0 when no lines are returned.

    Show child attributes
    • startintegerrequired

      The first line returned.

    • endintegerrequired

      The last line returned.

Other content types: text/markdowntext/plainapplication/octet-stream

jobs

Check the status of background jobs, such as builds and syncs.

Get a job

get/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/jobs/{jobId}

Returns the status of a background job: a build, an update, a sync, a restore or an apply. The endpoint that starts the work returns the job ID. Poll until status is succeeded, failed or cancelled. An ID that is not a job of this knowledge base returns 404 with code jobNotFound, and so does a job cancelled before it started, since it never ran. If background jobs are unavailable, the request returns 503 with code jobsUnavailable. Requires read access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • jobIdstringrequired

    The job ID returned by the endpoint that started the work.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Responses

200

A background job, such as a build, an update, a sync, a restore or an apply, and its status. kind says which, and determines the shape of result.

  • idstringrequired

    The job's ID. Treat it as an opaque string. Its format can change.

  • knowledgeBaseIdstringrequired

    The ID (kb…) of the knowledge base the job belongs to.

  • statusstringrequired

    The job's status. queued: waiting for earlier work on the knowledge base to finish, or for build capacity. running: in progress. succeeded: finished successfully. failed: stopped with an error. cancelled: stopped before it finished. succeeded, failed and cancelled are final. pending is reserved and isn't returned today.

  • startedAtrequired

    When the job started. Can be null while status is queued.

    Show child attributes
    • string (date-time)
  • completedAtrequired

    When the job finished. null while the job is queued or running.

    Show child attributes
    • string (date-time)
  • A readable reason the job failed or was cancelled. null for any other status.

    Show child attributes
    • string
  • kindstringrequired
  • resultobject

    The job's output. Only present when status is succeeded.

    Show child attributes
    • revisionIdstringrequired

      The revision the build produced.

    • entryCountintegerrequired

      How many entries the built outline has.

    • issuesCreatedintegerrequired

      How many issues the build filed.

    • criticalIssueCountintegerrequired

      How many questions the build left open for you to answer.

entries

Rebuild individual entries in a knowledge base. To read entries, query sanity.context.entry documents with GROQ.

Rebuild an entry from its sources

post/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/entries/{entryPath}/rebuild

Queues a rewrite of the entry at entryPath from its cited sources and the active instructions, and returns a job ID immediately. Only this entry is rewritten. The response also lists the other entries built from any of the same sources: an instruction applies to every entry built from its sources, so those entries can change when they are next rebuilt. Every rebuild of the same entry uses the same job ID, so a request made while one is waiting or running joins it. Returns 404 with code entryNotFound if the knowledge base has no entry at that path, and 422 with code entryDocumentInvalid if the entry document was edited into a shape the API cannot read. If background jobs are unavailable, the request returns 503 with code jobsUnavailable. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • entryPathstringrequired

    The entry's slash-delimited path, such as pricing/plans/free, URL-encoded.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Responses

202

The job that rebuilds the entry, and the other entries that share its sources.

  • jobIdstringrequired

    ID of the job that rebuilds the entry. Poll it with GET .../jobs/{jobId}.

  • affectedEntriesarrayrequired

    Other entries built from any of this entry's sources. An instruction applies to every entry built from its sources, so these entries can change when they are next rebuilt.

    Show child attributes
    items
    • idstringrequired

      The entry's document ID.

    • pathstringrequired

      The entry's path, such as products/api/webhooks.

    • titlestringrequired

      The entry's title.

issues

Triage the issues that builds and refreshes find.

Accept and apply issues

post/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/issues/apply

Accepts the issues in issueIds, then queues a job that applies them, rewrites the affected entries, and saves a new revision. Returns a job ID. Every apply in a knowledge base uses the same job ID. If an apply is already waiting to run, these issues join it. If one is already running, these issues are applied in a run that follows it, under the same ID. IDs of issues that no longer exist are skipped. Dismissed issues are skipped. If none of the IDs exist, the request still returns 202 and a job ID. Returns 409 with code issueNotAutoApplicable, and accepts none of the issues, if any of them cannot be applied: a conflict (resolve it with POST .../issues/{issueId}/resolve), or an update_required issue whose scopePath is * or names an entry that no longer exists. Dismiss those instead. Returns 409 with code issueTransitionConflict, and accepts none of the issues, if another change to one of them happened at the same time. Returns 422 with code issueDocumentInvalid if one of the issue documents was edited into a shape the API cannot verify. Returns 503 with code jobsUnavailable if the job cannot be queued. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Request body application/json

  • issueIdsarrayrequired

    The IDs of the issues to accept and apply.

    Show child attributes
    items
    • string

Responses

202

A queued job that you can poll for progress.

  • jobIdstringrequired

    The queued job's ID. Check its progress with GET .../jobs/{jobId}. Treat it as an opaque string. Its format can change.

Dismiss an issue

post/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/issues/{issueId}/dismiss

Marks the issue as rejected. If the issue already left triage, the request returns it unchanged. Returns 404 with code issueNotFound if the knowledge base has no issue with this ID. Returns 422 with code issueDocumentInvalid if the issue document was edited into a shape the API cannot verify. Returns 409 with code issueTransitionConflict if another change to the issue happened at the same time. You can safely retry a 409. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • issueIdstringrequired

    The issue's document ID, such as issue.01JD4M6X8Q2V7N3K5R9T0WYZAB. Find it by querying the knowledge base's sanity.context.issue documents with GROQ.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Responses

200

An issue found in a knowledge base, and its triage status.

  • idstringrequired

    The issue's document ID. A later build that finds the same issue in unchanged sources reuses this ID, so your triage decision is kept.

  • knowledgeBaseIdstringrequired

    The ID (kb...) of the knowledge base the issue belongs to.

  • contentrequired

    What an issue found. The shape depends on kind.

    Show child attributes
    • severitystringrequired

      How serious the issue is. critical: content is wrong or missing in a way that can mislead an agent. suggestion: a change that improves quality.

    • scopePathstringrequired

      Path of the entry the issue is about, or * when it applies to the whole knowledge base.

    • issuestringrequired

      What the problem is, in one or two sentences.

    • suggestedFixstringrequired

      What to do to fix the issue.

    • kindstringrequired

      The issue type. conflict means two or more positions disagree on the same fact, and you choose which one is correct.

    • claimKeystringrequired

      A key naming the disputed fact, such as free_tier.request_limit. It never includes the disputed value, so every side shares it.

    • contextstring

      One sentence that explains the question, when it needs one.

    • sidesarrayrequired

      The conflicting positions, at least two. To resolve the conflict, pass the index of one side as resolution, or 'all' when every side is correct for its own case.

      Show child attributes
      items
      • claimstringrequired

        The position as a self-contained sentence. This is the option you choose from.

      • valuestring

        The disputed value on its own, such as 10,000/month, without the sentence.

      • Paths of the entries that state this position.

        Show child attributes
        items
        • string
      • IDs of the documents that directly back this position.

        Show child attributes
        items
        • string
      • wherestring

        The documents that state this value, by the names you know them by.

      • Quotes from the documents that state this value, copied word for word and checked against each document. A document whose wording could not be checked has none.

        Show child attributes
        items
        • _keystringrequired

          Stable ID of this citation: 10 lowercase letters and digits. An entry body points to it with a [^key] marker.

        • _typestringrequired
        • documentIdstringrequired

          ID of the document the quote comes from. Read it with GET .../documents/{documentId}/content.

        • chunkIdstringrequired

          ID of the chunk of the document that holds the quote's first line. A chunk is the text under one heading, and keeps its ID across versions of the document while its headings stay the same.

        • titlestringrequired

          The document's name when the entry was written.

        • urlstring

          Where the document lives on the web. Absent for uploaded files and datasets.

        • quotestringrequired

          The passage from the document that backs the claims, copied word for word.

        • prefixstringrequired

          Up to 32 characters of document text just before the quote, to tell repeats apart.

        • suffixstringrequired

          Up to 32 characters of document text just after the quote, to tell repeats apart.

        • lineStartintegerrequired

          First line of the quote in the document, counting from 1. Line numbers match GET .../documents/{documentId}/content. A hint: the quote is the stable locator.

        • lineEndintegerrequired

          Last line of the quote, inclusive.

    • suggestedinteger

      Index in sides of the suggested side, when there is one. It is only a hint: nothing is chosen until you resolve the issue.

  • statusstringrequired

    The triage status. open: waiting for triage. accepted: accepted with POST .../issues/apply, or a conflict resolved to one side or to all sides. rejected: dismissed. A rejected issue stays rejected. You can return an accepted conflict to open with POST .../issues/{issueId}/reopen.

  • resolutionrequired

    How the conflict was resolved: the index in content.sides of the side chosen, or 'all' when every side was marked correct for its own case. For a conflict on a single entry, index 0 is the entry's current content. null until a conflict is resolved, and always null for other issue types.

    Show child attributes
    • integer
  • resolvedByrequired

    Who triaged the issue, so you can review what your agents decided. null while the issue is open, or when the caller could not be identified.

    Show child attributes
    • idstringrequired

      Sanity user ID of the person or robot that triaged the issue.

    • kindstringrequired

      user when a person made the decision. robot when a robot token did, such as an agent.

  • createdAtstring (date-time)required

    When the issue was first filed.

  • resolvedAtrequired

    When the issue left open. null while the issue is open.

    Show child attributes
    • string (date-time)

Resolve a conflict issue

post/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/issues/{issueId}/resolve

Resolves a conflict issue. Set resolution to the index of a side in content.sides, or to 'all' when every side is correct for its own case. The response's issue.resolvedBy records the caller, taken from the token. The decision is saved as an instruction with origin set to conflict, tied to the conflict's documents, and later builds apply it. If none of those documents still exist, no instruction is saved. For a conflict on a single entry, index 0 is the entry's current content and keeps it. Any other side also queues a rewrite of that entry, and jobId tracks it. In every other case, including a conflict whose scopePath is *, jobId is null. After saving the instruction, Sanity Context checks the entries built from its documents against it in the background. That check counts toward the organization's model spend and can file update_required issues for entries that contradict the decision. A resolved conflict is not asked again until one of its documents changes. To change a decision, resolve the accepted conflict again. Other issue types, dismissed conflicts, and out-of-range indexes return 422 with code issueNotResolvable. Choosing a side that rewrites an entry that no longer exists returns 409 with code issueNotAutoApplicable. Returns 404 with code issueNotFound if the knowledge base has no issue with this ID, 422 with code issueDocumentInvalid if the issue document was edited into a shape the API cannot verify, and 409 with code issueTransitionConflict if another change to the issue happened at the same time. If the rewrite cannot be queued, the request returns 503 with code jobsUnavailable after the decision is saved. Retry the same request to queue the rewrite. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • issueIdstringrequired

    The issue's document ID, such as issue.01JD4M6X8Q2V7N3K5R9T0WYZAB. Find it by querying the knowledge base's sanity.context.issue documents with GROQ.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Request body application/json

  • resolutionrequired

    The index of the chosen side in the issue's content.sides, or 'all' when every side is correct for its own case.

    Show child attributes
    • integer

Responses

200

The resolved issue, plus the job that rewrites the entry, if any.

  • issueobjectrequired

    An issue found in a knowledge base, and its triage status.

    Show child attributes
    • idstringrequired

      The issue's document ID. A later build that finds the same issue in unchanged sources reuses this ID, so your triage decision is kept.

    • knowledgeBaseIdstringrequired

      The ID (kb...) of the knowledge base the issue belongs to.

    • contentrequired

      What an issue found. The shape depends on kind.

      Show child attributes
      • severitystringrequired

        How serious the issue is. critical: content is wrong or missing in a way that can mislead an agent. suggestion: a change that improves quality.

      • scopePathstringrequired

        Path of the entry the issue is about, or * when it applies to the whole knowledge base.

      • issuestringrequired

        What the problem is, in one or two sentences.

      • suggestedFixstringrequired

        What to do to fix the issue.

      • kindstringrequired

        The issue type. conflict means two or more positions disagree on the same fact, and you choose which one is correct.

      • claimKeystringrequired

        A key naming the disputed fact, such as free_tier.request_limit. It never includes the disputed value, so every side shares it.

      • contextstring

        One sentence that explains the question, when it needs one.

      • sidesarrayrequired

        The conflicting positions, at least two. To resolve the conflict, pass the index of one side as resolution, or 'all' when every side is correct for its own case.

        Show child attributes
        items
        • claimstringrequired

          The position as a self-contained sentence. This is the option you choose from.

        • valuestring

          The disputed value on its own, such as 10,000/month, without the sentence.

        • Paths of the entries that state this position.

          Show child attributes
          items
          • string
        • IDs of the documents that directly back this position.

          Show child attributes
          items
          • string
        • wherestring

          The documents that state this value, by the names you know them by.

        • Quotes from the documents that state this value, copied word for word and checked against each document. A document whose wording could not be checked has none.

          Show child attributes
          items
          • _keystringrequired

            Stable ID of this citation: 10 lowercase letters and digits. An entry body points to it with a [^key] marker.

          • _typestringrequired
          • documentIdstringrequired

            ID of the document the quote comes from. Read it with GET .../documents/{documentId}/content.

          • chunkIdstringrequired

            ID of the chunk of the document that holds the quote's first line. A chunk is the text under one heading, and keeps its ID across versions of the document while its headings stay the same.

          • titlestringrequired

            The document's name when the entry was written.

          • urlstring

            Where the document lives on the web. Absent for uploaded files and datasets.

          • quotestringrequired

            The passage from the document that backs the claims, copied word for word.

          • prefixstringrequired

            Up to 32 characters of document text just before the quote, to tell repeats apart.

          • suffixstringrequired

            Up to 32 characters of document text just after the quote, to tell repeats apart.

          • lineStartintegerrequired

            First line of the quote in the document, counting from 1. Line numbers match GET .../documents/{documentId}/content. A hint: the quote is the stable locator.

          • lineEndintegerrequired

            Last line of the quote, inclusive.

      • suggestedinteger

        Index in sides of the suggested side, when there is one. It is only a hint: nothing is chosen until you resolve the issue.

    • statusstringrequired

      The triage status. open: waiting for triage. accepted: accepted with POST .../issues/apply, or a conflict resolved to one side or to all sides. rejected: dismissed. A rejected issue stays rejected. You can return an accepted conflict to open with POST .../issues/{issueId}/reopen.

    • resolutionrequired

      How the conflict was resolved: the index in content.sides of the side chosen, or 'all' when every side was marked correct for its own case. For a conflict on a single entry, index 0 is the entry's current content. null until a conflict is resolved, and always null for other issue types.

      Show child attributes
      • integer
    • resolvedByrequired

      Who triaged the issue, so you can review what your agents decided. null while the issue is open, or when the caller could not be identified.

      Show child attributes
      • idstringrequired

        Sanity user ID of the person or robot that triaged the issue.

      • kindstringrequired

        user when a person made the decision. robot when a robot token did, such as an agent.

    • createdAtstring (date-time)required

      When the issue was first filed.

    • resolvedAtrequired

      When the issue left open. null while the issue is open.

      Show child attributes
      • string (date-time)
  • jobIdrequired

    ID of the job that rewrites the entry, which you can poll with GET .../jobs/{jobId}. null when nothing is rewritten: you resolved the conflict as 'all', its scopePath is *, or you chose index 0 of a single-entry conflict. The decision is saved as an instruction the next build applies.

    Show child attributes
    • string

Reopen an accepted conflict

post/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/issues/{issueId}/reopen

Returns an accepted conflict issue to triage, clears its resolution, and deletes the instruction the resolution created. It also deletes the open issues filed for entries that contradict that instruction. Reopening does not undo an entry rewrite the resolution already queued. Reopening an open or dismissed conflict returns it unchanged. Other issue types return 422 with code issueNotResolvable. Returns 404 with code issueNotFound if the knowledge base has no issue with this ID, 422 with code issueDocumentInvalid if the issue document was edited into a shape the API cannot verify, and 409 with code issueTransitionConflict if another change to the issue happened at the same time. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • issueIdstringrequired

    The issue's document ID, such as issue.01JD4M6X8Q2V7N3K5R9T0WYZAB. Find it by querying the knowledge base's sanity.context.issue documents with GROQ.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Responses

200

An issue found in a knowledge base, and its triage status.

  • idstringrequired

    The issue's document ID. A later build that finds the same issue in unchanged sources reuses this ID, so your triage decision is kept.

  • knowledgeBaseIdstringrequired

    The ID (kb...) of the knowledge base the issue belongs to.

  • contentrequired

    What an issue found. The shape depends on kind.

    Show child attributes
    • severitystringrequired

      How serious the issue is. critical: content is wrong or missing in a way that can mislead an agent. suggestion: a change that improves quality.

    • scopePathstringrequired

      Path of the entry the issue is about, or * when it applies to the whole knowledge base.

    • issuestringrequired

      What the problem is, in one or two sentences.

    • suggestedFixstringrequired

      What to do to fix the issue.

    • kindstringrequired

      The issue type. conflict means two or more positions disagree on the same fact, and you choose which one is correct.

    • claimKeystringrequired

      A key naming the disputed fact, such as free_tier.request_limit. It never includes the disputed value, so every side shares it.

    • contextstring

      One sentence that explains the question, when it needs one.

    • sidesarrayrequired

      The conflicting positions, at least two. To resolve the conflict, pass the index of one side as resolution, or 'all' when every side is correct for its own case.

      Show child attributes
      items
      • claimstringrequired

        The position as a self-contained sentence. This is the option you choose from.

      • valuestring

        The disputed value on its own, such as 10,000/month, without the sentence.

      • Paths of the entries that state this position.

        Show child attributes
        items
        • string
      • IDs of the documents that directly back this position.

        Show child attributes
        items
        • string
      • wherestring

        The documents that state this value, by the names you know them by.

      • Quotes from the documents that state this value, copied word for word and checked against each document. A document whose wording could not be checked has none.

        Show child attributes
        items
        • _keystringrequired

          Stable ID of this citation: 10 lowercase letters and digits. An entry body points to it with a [^key] marker.

        • _typestringrequired
        • documentIdstringrequired

          ID of the document the quote comes from. Read it with GET .../documents/{documentId}/content.

        • chunkIdstringrequired

          ID of the chunk of the document that holds the quote's first line. A chunk is the text under one heading, and keeps its ID across versions of the document while its headings stay the same.

        • titlestringrequired

          The document's name when the entry was written.

        • urlstring

          Where the document lives on the web. Absent for uploaded files and datasets.

        • quotestringrequired

          The passage from the document that backs the claims, copied word for word.

        • prefixstringrequired

          Up to 32 characters of document text just before the quote, to tell repeats apart.

        • suffixstringrequired

          Up to 32 characters of document text just after the quote, to tell repeats apart.

        • lineStartintegerrequired

          First line of the quote in the document, counting from 1. Line numbers match GET .../documents/{documentId}/content. A hint: the quote is the stable locator.

        • lineEndintegerrequired

          Last line of the quote, inclusive.

    • suggestedinteger

      Index in sides of the suggested side, when there is one. It is only a hint: nothing is chosen until you resolve the issue.

  • statusstringrequired

    The triage status. open: waiting for triage. accepted: accepted with POST .../issues/apply, or a conflict resolved to one side or to all sides. rejected: dismissed. A rejected issue stays rejected. You can return an accepted conflict to open with POST .../issues/{issueId}/reopen.

  • resolutionrequired

    How the conflict was resolved: the index in content.sides of the side chosen, or 'all' when every side was marked correct for its own case. For a conflict on a single entry, index 0 is the entry's current content. null until a conflict is resolved, and always null for other issue types.

    Show child attributes
    • integer
  • resolvedByrequired

    Who triaged the issue, so you can review what your agents decided. null while the issue is open, or when the caller could not be identified.

    Show child attributes
    • idstringrequired

      Sanity user ID of the person or robot that triaged the issue.

    • kindstringrequired

      user when a person made the decision. robot when a robot token did, such as an agent.

  • createdAtstring (date-time)required

    When the issue was first filed.

  • resolvedAtrequired

    When the issue left open. null while the issue is open.

    Show child attributes
    • string (date-time)

instructions

Create standing instructions that steer every build.

Create an instruction

post/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/instructions

Creates a standing instruction for how entries built from its documents are written. Every instruction applies to specific documents, set in scopeDocumentIds. To rebuild entries under the new instruction right away, pass their paths in rebuildPaths. The response includes the rebuild job ID, or null if the rebuild could not start. The instruction is saved either way. After the instruction is saved, a background check files issues for entries that contradict it. If you already checked the instruction for contradictions, set verified to skip the background check. If the requested rebuild does not start, the background check runs even when verified is set. The background check counts toward the organization's model spend. Each request creates a new instruction, so retrying a request that may have succeeded can create a duplicate. Returns 422 with code instructionScopeVanished if none of the documents in scopeDocumentIds exist. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Request body application/json

  • statementstringrequired

    The instruction in plain language. Builds follow it over what the sources say.

  • scopeDocumentIdsarrayrequired

    IDs of the documents the instruction applies to. Builds apply it when they write entries built from these documents. IDs of documents that no longer exist are dropped. If none exist, the request returns 422 with code instructionScopeVanished.

    Show child attributes
    items
    • string (uuid)
  • Paths of entries to rebuild under the new instruction right away. The response returns the rebuild job ID in rebuildJobId.

    Show child attributes
    items
    • string
  • verifiedboolean

    Whether you already checked the instruction for entries that contradict it. When true, the background check that files issues for those entries is skipped. It still runs if the rebuild you requested in rebuildPaths does not start.

Responses

201

The created instruction, and the rebuild it started.

  • instructionobjectrequired

    The created instruction.

    Show child attributes
    • idstringrequired

      The instruction's document ID.

    • knowledgeBaseIdstringrequired

      The ID (kb...) of the knowledge base the instruction belongs to.

    • originstringrequired

      How the instruction was created. human: someone wrote it. conflict: it records the side chosen, or that every side is correct, when a conflict issue was resolved. Both kinds work the same way in builds.

    • statusstringrequired

      Whether builds apply the instruction. active: builds apply it. archived: a refresh found that its documents no longer support it, so builds stop applying it. To reactivate an archived instruction, update it.

    • statementstringrequired

      The instruction in plain language. Builds follow it over what the sources say.

    • scopeDocumentIdsarrayrequired

      IDs of the documents the instruction applies to. Builds apply it when they write entries built from these documents. An empty array means all of its documents were removed, so it applies to no entries.

      Show child attributes
      items
      • string (uuid)
    • archivedAtrequired

      When a refresh archived the instruction. null while it is active.

      Show child attributes
      • string (date-time)
    • Why the instruction was archived. null while it is active.

      Show child attributes
      • string
    • ID of the conflict issue this instruction records. null when origin is human.

      Show child attributes
      • string
    • createdByrequired

      Who created the instruction. null for instructions created by resolving a conflict, and when the creator is unknown.

      Show child attributes
      • idrequired

        The Sanity user ID, or sanity-system when Sanity Context made the change. null if unknown.

        Show child attributes
        • string
      • displayNamerequired

        The user's name when the action happened. null if unknown. For the current name, look up the user by id.

        Show child attributes
        • string
    • updatedByrequired

      Who last updated the instruction through the API. null when it was never updated, or when the person is unknown.

      Show child attributes
      • idrequired

        The Sanity user ID, or sanity-system when Sanity Context made the change. null if unknown.

        Show child attributes
        • string
      • displayNamerequired

        The user's name when the action happened. null if unknown. For the current name, look up the user by id.

        Show child attributes
        • string
    • createdAtstring (date-time)required

      When the instruction was created.

    • updatedAtrequired

      When the instruction last changed, including changes a refresh makes. null when the time is unknown.

      Show child attributes
      • string (date-time)
  • rebuildJobIdrequired

    ID of the job that rebuilds the entries in rebuildPaths. Poll it with GET .../jobs/{jobId}. null when you didn't pass rebuildPaths or the rebuild could not start. The instruction is saved either way.

    Show child attributes
    • string

Check an instruction for contradictions

post/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/instructions/check

Checks every entry built from any of the documents in scopeDocumentIds against statement, and returns the entries that contradict it. Nothing is saved. Run it before POST .../instructions to find the entries a new instruction would contradict, then pass their paths as rebuildPaths and set verified. Each checked entry is one model call that counts toward the organization's model spend, and the response waits for all of them, so a check over many entries can take a while. To list the entries without checking them, set candidatesOnly; this makes no model calls. To check only some entries, pass their paths in paths. Together, these let you check one entry per request and show progress. Although it saves nothing, as a POST it needs the same access as a write. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Request body application/json

  • statementstringrequired

    The instruction in plain language, as you would pass it to create.

  • scopeDocumentIdsarrayrequired

    IDs of the documents the instruction will be tied to. The check covers every entry built from any of them.

    Show child attributes
    items
    • string (uuid)
  • ID of an entry to leave out of the check, such as the entry the instruction was drafted from.

  • Set to true to list the entries the check would cover in candidates without checking them. This makes no model calls.

  • pathsarray

    Paths of the entries to check. Paths of entries the check would not cover are ignored. Omit it to check every entry built from the documents.

    Show child attributes
    items
    • string

Responses

200

The result of checking an instruction. Nothing is saved.

  • checkedintegerrequired

    How many entries were checked. Entries with no text, and entries whose check failed, are not counted and not reported. 0 when candidatesOnly is set.

  • contradictionsarrayrequired

    The entries that contradict the instruction, ordered by path. Empty when candidatesOnly is set.

    Show child attributes
    items
    • idstringrequired

      The entry's document ID.

    • pathstringrequired

      The entry's path, such as products/api/webhooks.

    • titlestringrequired

      The entry's title.

    • issuestringrequired

      What the entry says now, and why it contradicts the instruction.

  • The entries the check covers, ordered by path. Only present when candidatesOnly is set.

    Show child attributes
    items
    • idstringrequired

      The entry's document ID.

    • pathstringrequired

      The entry's path, such as products/api/webhooks.

    • titlestringrequired

      The entry's title.

Draft an instruction from feedback

post/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/instructions/draft

Turns free-form feedback, such as "this is wrong" or "never say X", into a proposed instruction: a statement and the documents it applies to. The documents come from scopeDocumentIds if you set it, or otherwise from the documents of the entry in entryId. Nothing is saved. Review and edit the draft, then create it with POST .../instructions. Each draft is one model call that counts toward the organization's model spend. If the model call fails, the request returns 502 with code instructionDraftFailed. Retry, or write the instruction yourself. Returns 404 with code entryNotFound if entryId names no entry, and 422 with code instructionScopeVanished if neither scopeDocumentIds nor the entry gives any documents. Although it saves nothing, as a POST it needs the same access as a write. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Request body application/json

  • feedbackstringrequired

    What should change, in your own words, such as "this is wrong" or "never say X".

  • entryIdstring

    ID of the entry the feedback is about. The draft reads the entry and its documents for context. If the entry doesn't exist, the request returns 404 with code entryNotFound.

  • excerptstring

    The passage of the entry the feedback is about, so the draft addresses that claim.

  • IDs of the documents to tie the instruction to. Omit it to use the documents of the entry in entryId. If neither gives any documents, the request returns 422 with code instructionScopeVanished.

    Show child attributes
    items
    • string (uuid)

Responses

200

A proposed instruction. Nothing is saved: pass it to POST .../instructions to create it.

  • statementstringrequired

    The proposed instruction in plain language, written as a standing rule.

  • scopeDocumentIdsarrayrequired

    IDs of the documents the instruction should be tied to: scopeDocumentIds from the request, or the documents of the entry in entryId. Always at least one.

    Show child attributes
    items
    • string (uuid)

Update an instruction

patch/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/instructions/{instructionId}

Updates the instruction's statement or documents. The change applies from the next build. Any update also reactivates an archived instruction and ties it to the current content of its documents. Updating deletes the open issues filed for entries that contradict the instruction. Sanity Context then checks the entries built from its documents against the updated instruction in the background. That check counts toward the organization's model spend and can file new update_required issues. Returns 404 with code instructionNotFound if the knowledge base has no instruction with this ID. Returns 422 with code instructionScopeVanished if none of the documents in scopeDocumentIds exist. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • instructionIdstringrequired

    The instruction's document ID, such as instruction.01JD5B2C7E9F3G6H8J0K4M1N5P. Find it by querying the knowledge base's sanity.context.instruction documents with GROQ, or take it from instruction.id in the create response.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Request body application/json

  • statementstring

    The new instruction text. Omit it to keep the current text.

  • IDs of the documents the instruction applies to. Replaces the current list. Omit it to keep the current documents. IDs of documents that no longer exist are dropped. If none exist, the request returns 422 with code instructionScopeVanished.

    Show child attributes
    items
    • string (uuid)

Responses

200

A standing instruction that shapes how entries built from its documents are written.

  • idstringrequired

    The instruction's document ID.

  • knowledgeBaseIdstringrequired

    The ID (kb...) of the knowledge base the instruction belongs to.

  • originstringrequired

    How the instruction was created. human: someone wrote it. conflict: it records the side chosen, or that every side is correct, when a conflict issue was resolved. Both kinds work the same way in builds.

  • statusstringrequired

    Whether builds apply the instruction. active: builds apply it. archived: a refresh found that its documents no longer support it, so builds stop applying it. To reactivate an archived instruction, update it.

  • statementstringrequired

    The instruction in plain language. Builds follow it over what the sources say.

  • scopeDocumentIdsarrayrequired

    IDs of the documents the instruction applies to. Builds apply it when they write entries built from these documents. An empty array means all of its documents were removed, so it applies to no entries.

    Show child attributes
    items
    • string (uuid)
  • archivedAtrequired

    When a refresh archived the instruction. null while it is active.

    Show child attributes
    • string (date-time)
  • Why the instruction was archived. null while it is active.

    Show child attributes
    • string
  • ID of the conflict issue this instruction records. null when origin is human.

    Show child attributes
    • string
  • createdByrequired

    Who created the instruction. null for instructions created by resolving a conflict, and when the creator is unknown.

    Show child attributes
    • idrequired

      The Sanity user ID, or sanity-system when Sanity Context made the change. null if unknown.

      Show child attributes
      • string
    • displayNamerequired

      The user's name when the action happened. null if unknown. For the current name, look up the user by id.

      Show child attributes
      • string
  • updatedByrequired

    Who last updated the instruction through the API. null when it was never updated, or when the person is unknown.

    Show child attributes
    • idrequired

      The Sanity user ID, or sanity-system when Sanity Context made the change. null if unknown.

      Show child attributes
      • string
    • displayNamerequired

      The user's name when the action happened. null if unknown. For the current name, look up the user by id.

      Show child attributes
      • string
  • createdAtstring (date-time)required

    When the instruction was created.

  • updatedAtrequired

    When the instruction last changed, including changes a refresh makes. null when the time is unknown.

    Show child attributes
    • string (date-time)

Delete an instruction

delete/{apiVersion}/context/knowledge-bases/{knowledgeBaseId}/instructions/{instructionId}

Deletes the instruction. Builds stop applying it from the next run. Entries already written under it keep their text until they are rebuilt; pass rebuild=true to rebuild every entry built from its documents right away. Deleting also deletes the open issues filed for entries that contradict the instruction. Returns 404 with code instructionNotFound if the knowledge base has no instruction with this ID, including one you already deleted. Requires update access to the knowledge base.

Path parameters

  • knowledgeBaseIdstringrequired

    The knowledge base's ID (kb...), its publicId. Its UUID id is also accepted.

  • instructionIdstringrequired

    The instruction's document ID, such as instruction.01JD5B2C7E9F3G6H8J0K4M1N5P. Find it by querying the knowledge base's sanity.context.instruction documents with GROQ, or take it from instruction.id in the create response.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03

Query parameters

  • rebuildstring

    Set to true to rebuild every entry built from the instruction's documents once it is deleted, so pages written under the instruction reflect their documents again. The response returns the rebuild job ID in rebuildJobId.

Responses

200

The rebuild the delete started, if any.

  • rebuildJobIdrequired

    ID of the job that rebuilds the entries built from the instruction's documents. Poll it with GET .../jobs/{jobId}. null when you didn't pass rebuild=true, no entry is built from those documents, or the rebuild could not start. The instruction is deleted either way.

    Show child attributes
    • string

mcp

Create and configure the Model Context Protocol (MCP) endpoints agents connect to, and check whether they are ready.

Create an MCP endpoint

post/{apiVersion}/context/organizations/{organizationId}/mcp

Creates an MCP endpoint with a title, a name, and the sources it serves. A source is a knowledge base, identified by its ID (kb…), or a dataset, identified as <projectId>.<datasetName>. An endpoint can serve any number of knowledge bases and at most one dataset, all at once. A GROQ filter is only kept when the endpoint has a dataset. The name must be unique in your organization, and you can't change it later. Duplicate sources with the same type and id are combined. The response includes the url agents connect to. To list or inspect endpoints, query sanity.context.mcp documents with GROQ from your organization's document store. Requires the sanity.context.mcp.create grant on the organization, which the Administrator and Developer roles have. Adding a dataset also requires full read access to the dataset and, on its project, the Administrator or Developer role or a custom role that can create datasets.

Without the grant, the request returns 403 with code mcpEndpointManageAccessDenied. Without the dataset access, it returns 403 with code projectAdminRequired or datasetReadAccessDenied. A taken name returns 409 with code mcpEndpointNameConflict. A knowledge base that doesn't exist in the organization returns 422 with code mcpSourceKnowledgeBaseNotFound, and an invalid GROQ filter returns 422 with code invalidGroqFilter.

Path parameters

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03
  • organizationIdstringrequired

    The ID of the organization.

Request body application/json

  • titlestringrequired

    The endpoint's display title, up to 100 characters.

  • namestringrequired

    The endpoint's name, used in its URL. Lowercase letters, digits and single hyphens, up to 64 characters, unique in the organization. It can't be changed after the endpoint is created. by-name and names shaped like an endpoint ID are reserved.

  • sourcesarrayrequired

    The content the endpoint serves: up to 100 sources, any number of knowledge bases and at most one dataset, served together. Order has no meaning. With no sources, agents can't connect until one is added.

    Show child attributes
    items
    • typestringrequired

      The source type. knowledge-base serves a whole knowledge base.

    • idstringrequired

      The knowledge base ID (kb…).

  • Instructions for connecting agents, up to 10,000 characters.

  • A GROQ filter that limits which documents the endpoint's dataset source serves, such as _type in ["post", "author"]. Knowledge base sources aren't filtered. Kept only while the endpoint has a dataset source.

Responses

201

An MCP endpoint: a URL that serves knowledge bases and at most one dataset to agents over the Model Context Protocol (MCP).

  • idstringrequired

    The endpoint's ID (mcp…). Update and delete accept it or the endpoint's name.

  • organizationIdstringrequired

    The ID of the organization that owns the endpoint.

  • titlestringrequired

    The endpoint's display title.

  • namestringrequired

    The endpoint's name, used in its URL. It can't be changed.

  • sourcesarrayrequired

    The content the endpoint serves: any number of knowledge bases and at most one dataset, served together. With no sources, agents can't connect until one is added.

    Show child attributes
    items
    • typestringrequired

      The source type. knowledge-base serves a whole knowledge base.

    • idstringrequired

      The knowledge base ID (kb…).

  • instructionsrequired

    Instructions for connecting agents, or null if none are set.

    Show child attributes
    • string
  • groqFilterrequired

    The GROQ filter that limits the endpoint's dataset source, or null if none is set or the endpoint has no dataset.

    Show child attributes
    • string
  • urlstring (uri)required

    The URL agents connect to.

  • createdAtstring (date-time)required

    When the endpoint was created, as an ISO 8601 timestamp.

  • updatedAtstring (date-time)required

    When the endpoint was last edited, as an ISO 8601 timestamp. Agents using the endpoint don't change it.

  • lastUsedAtrequired

    When an agent last used the endpoint, as an ISO 8601 timestamp. It's recorded at most once every 10 minutes, so it can be up to 10 minutes behind. null if the endpoint hasn't been used since usage tracking started.

    Show child attributes
    • string (date-time)

Update an MCP endpoint

patch/{apiVersion}/context/organizations/{organizationId}/mcp/{mcpEndpoint}

Updates the title, sources, instructions, or GROQ filter of the endpoint with that name or ID. To clear an optional field, set it to null. An endpoint can have at most one dataset source, and removing it clears the GROQ filter. You can't change the name, so the endpoint URL stays the same. Requires the sanity.context.mcp.update grant on the organization. Adding a dataset source requires full read access to the dataset and, on its project, the Administrator or Developer role or a custom role that can create datasets. Changing the GROQ filter or the dataset source's perspective requires the same access for the endpoint's dataset. Sending the current values changes nothing.

Without the grant, the request returns 403 with code mcpEndpointManageAccessDenied. Without the dataset access, it returns 403 with code projectAdminRequired or datasetReadAccessDenied. An unknown endpoint returns 404 with code mcpEndpointNotFound. A knowledge base that doesn't exist in the organization returns 422 with code mcpSourceKnowledgeBaseNotFound, and an invalid GROQ filter returns 422 with code invalidGroqFilter. If the endpoint changed while the update was in progress, the update returns 409 with code mcpEndpointEditConflict and changes nothing. You can safely retry it.

Path parameters

  • mcpEndpointstringrequired

    The MCP endpoint's name, as in its URL, or its ID (mcp…). Names can't take the shape of an ID, so either one identifies the endpoint.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03
  • organizationIdstringrequired

    The ID of the organization.

Request body application/json

  • titlestring

    The endpoint's display title, up to 100 characters.

  • sourcesarray

    The content the endpoint serves: up to 100 sources, any number of knowledge bases and at most one dataset, served together. Order has no meaning. With no sources, agents can't connect until one is added.

    Show child attributes
    items
    • typestringrequired

      The source type. knowledge-base serves a whole knowledge base.

    • idstringrequired

      The knowledge base ID (kb…).

  • Instructions for connecting agents, up to 10,000 characters. null removes them.

    Show child attributes
    • string

      Instructions for connecting agents, up to 10,000 characters.

  • A GROQ filter that limits the endpoint's dataset source. null removes it.

    Show child attributes
    • string

      A GROQ filter that limits which documents the endpoint's dataset source serves, such as _type in ["post", "author"]. Knowledge base sources aren't filtered. Kept only while the endpoint has a dataset source.

Responses

200

An MCP endpoint: a URL that serves knowledge bases and at most one dataset to agents over the Model Context Protocol (MCP).

  • idstringrequired

    The endpoint's ID (mcp…). Update and delete accept it or the endpoint's name.

  • organizationIdstringrequired

    The ID of the organization that owns the endpoint.

  • titlestringrequired

    The endpoint's display title.

  • namestringrequired

    The endpoint's name, used in its URL. It can't be changed.

  • sourcesarrayrequired

    The content the endpoint serves: any number of knowledge bases and at most one dataset, served together. With no sources, agents can't connect until one is added.

    Show child attributes
    items
    • typestringrequired

      The source type. knowledge-base serves a whole knowledge base.

    • idstringrequired

      The knowledge base ID (kb…).

  • instructionsrequired

    Instructions for connecting agents, or null if none are set.

    Show child attributes
    • string
  • groqFilterrequired

    The GROQ filter that limits the endpoint's dataset source, or null if none is set or the endpoint has no dataset.

    Show child attributes
    • string
  • urlstring (uri)required

    The URL agents connect to.

  • createdAtstring (date-time)required

    When the endpoint was created, as an ISO 8601 timestamp.

  • updatedAtstring (date-time)required

    When the endpoint was last edited, as an ISO 8601 timestamp. Agents using the endpoint don't change it.

  • lastUsedAtrequired

    When an agent last used the endpoint, as an ISO 8601 timestamp. It's recorded at most once every 10 minutes, so it can be up to 10 minutes behind. null if the endpoint hasn't been used since usage tracking started.

    Show child attributes
    • string (date-time)

Delete an MCP endpoint

delete/{apiVersion}/context/organizations/{organizationId}/mcp/{mcpEndpoint}

Deletes the MCP endpoint with that name or ID. Agents connected through it lose access, and its name can be used again. Requires the sanity.context.mcp.delete grant on the organization. Without it, the request returns 403 with code mcpEndpointManageAccessDenied. An unknown endpoint returns 404 with code mcpEndpointNotFound.

Path parameters

  • mcpEndpointstringrequired

    The MCP endpoint's name, as in its URL, or its ID (mcp…). Names can't take the shape of an ID, so either one identifies the endpoint.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03
  • organizationIdstringrequired

    The ID of the organization.

Responses

204

No content.

Get an MCP endpoint's initial context

get/{apiVersion}/context/organizations/{organizationId}/mcp/{mcpEndpoint}/initial-context

Returns the same text as the initial_context MCP tool, as plain text you can add to a system prompt. heading_offset shifts markdown headings down by that many levels. The default is 1, so # becomes ##. A call counts as use of the endpoint in its lastUsedAt. Requires access to the organization and the sanity.knowledge-base.read grant on each knowledge base the endpoint serves. When the endpoint serves a dataset, it also requires the sanity.knowledge-base.read grant on all knowledge bases in the organization.

An unknown endpoint returns 404 with code mcpEndpointNotFound. Without the grant on all knowledge bases, an endpoint with a dataset returns 403 with code contextGrantRequired. Without read access to one of its knowledge bases, it returns 403 with code knowledgeBaseAccessDenied. An endpoint that can't be served returns 400 with code mcpEndpointNotServable: it has no sources, none of its knowledge bases exist, or its dataset has no deployed studio or lacks the configured workspace.

Path parameters

  • mcpEndpointstringrequired

    The MCP endpoint's name, set when the endpoint was created.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03
  • organizationIdstringrequired

    The ID of the organization.

Query parameters

  • instructionsstringdeprecated

    Agent instructions that replace the endpoint's configured instructions for this request. Deprecated: refused from API version v2026-11-03. Configure it on the MCP endpoint instead.

  • perspectivestringdeprecated

    The perspective for GROQ queries: published (default), previewDrafts, raw, or a release. Deprecated: refused from API version v2026-11-03. Configure it on the MCP endpoint instead.

  • embeddingsstringdeprecated

    Set to true or false to turn semantic search on or off. Omit it to use the dataset source setting. Deprecated: refused from API version v2026-11-03. Configure it on the MCP endpoint instead.

  • groqFilterstringdeprecated

    A GROQ filter that narrows the endpoint's configured content filter for this request. Documents must match both. Deprecated: refused from API version v2026-11-03. Configure it on the MCP endpoint instead.

  • modestringdeprecated

    Serves only one side of the endpoint for this request: knowledge_base serves its knowledge bases and groq serves its dataset. Omit it to serve every source the endpoint has. A request whose chosen side the endpoint doesn't have is refused. Deprecated: refused from API version v2026-11-03. Configure it on the MCP endpoint instead.

  • knowledgeBasesstringdeprecated

    Comma-separated knowledge base public IDs (kb...) that replace the endpoint's knowledge base sources for this request. Deprecated: refused from API version v2026-11-03. Configure it on the MCP endpoint instead.

  • A JSON array that adds _url fields to query results. Each item has types (document types), baseUrl, and an optional slugExpression, a GROQ expression that defaults to slug.current. Invalid JSON is ignored.

  • workspacestringdeprecated

    The studio workspace to use. Replaces the dataset source's workspace for this request. Deprecated: refused from API version v2026-11-03. Configure it on the MCP endpoint instead.

  • How many levels to shift markdown headings down, from 0 to 6. Defaults to 1, so # becomes ##. Numbers outside that range are clamped to it, decimals are rounded toward zero, and a value that isn't a number uses 1.

Responses

200

The endpoint's initial context: Markdown, sent as plain text.

  • string

Check an MCP endpoint

get/{apiVersion}/context/organizations/{organizationId}/mcp/{mcpEndpoint}/status

Checks whether the endpoint is ready for agents, and whether your credentials can read what it serves. A failed check returns 200 with that check's ok set to false, so you can see every problem at once. ready summarizes the result. Requires access to the organization. Read access to the endpoint's knowledge bases isn't required: the access check reports what you can't read. When the endpoint serves a dataset, it requires the sanity.knowledge-base.read grant on all knowledge bases in the organization.

An unknown endpoint returns 404 with code mcpEndpointNotFound. Without the grant on all knowledge bases, an endpoint with a dataset returns 403 with code contextGrantRequired instead of running the checks.

Path parameters

  • mcpEndpointstringrequired

    The MCP endpoint's name, set when the endpoint was created.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03
  • organizationIdstringrequired

    The ID of the organization.

Query parameters

  • instructionsstringdeprecated

    Agent instructions that replace the endpoint's configured instructions for this request. Deprecated: refused from API version v2026-11-03. Configure it on the MCP endpoint instead.

  • perspectivestringdeprecated

    The perspective for GROQ queries: published (default), previewDrafts, raw, or a release. Deprecated: refused from API version v2026-11-03. Configure it on the MCP endpoint instead.

  • embeddingsstringdeprecated

    Set to true or false to turn semantic search on or off. Omit it to use the dataset source setting. Deprecated: refused from API version v2026-11-03. Configure it on the MCP endpoint instead.

  • groqFilterstringdeprecated

    A GROQ filter that narrows the endpoint's configured content filter for this request. Documents must match both. Deprecated: refused from API version v2026-11-03. Configure it on the MCP endpoint instead.

  • modestringdeprecated

    Serves only one side of the endpoint for this request: knowledge_base serves its knowledge bases and groq serves its dataset. Omit it to serve every source the endpoint has. A request whose chosen side the endpoint doesn't have is refused. Deprecated: refused from API version v2026-11-03. Configure it on the MCP endpoint instead.

  • knowledgeBasesstringdeprecated

    Comma-separated knowledge base public IDs (kb...) that replace the endpoint's knowledge base sources for this request. Deprecated: refused from API version v2026-11-03. Configure it on the MCP endpoint instead.

  • A JSON array that adds _url fields to query results. Each item has types (document types), baseUrl, and an optional slugExpression, a GROQ expression that defaults to slug.current. Invalid JSON is ignored.

  • workspacestringdeprecated

    The studio workspace to use. Replaces the dataset source's workspace for this request. Deprecated: refused from API version v2026-11-03. Configure it on the MCP endpoint instead.

Responses

200

Whether the MCP endpoint is ready for agents, and the result of each check.

  • readybooleanrequired

    Whether every check that applies to the connection passed, except semanticSearch and access. When true, the endpoint is ready for an agent whose credentials can read what it serves.

  • requiredOkbooleanrequireddeprecated

    Deprecated: use ready, which always has the same value.

  • checksobjectrequired

    One result per check. A check is null when it doesn't apply to the connection.

    Show child attributes
    • studiorequired

      Whether a deployed studio serves the endpoint's dataset. Its schema tells the agent which document types exist. null when the connection doesn't query a dataset.

      Show child attributes
      • okbooleanrequired

        The check passed.

      • workspacestringrequired

        The name of the studio workspace the connection uses.

      • workspaceTitlestringrequired

        The workspace's title.

      • workspaceAutoSelectedbooleanrequired

        Whether the workspace was picked automatically because none was set. It is false when the dataset source's workspace chose it, or a workspace query parameter on versions before v2026-11-03.

      • availableWorkspacesarrayrequired

        The deployed studio's workspaces for the endpoint's dataset.

        Show child attributes
        items
        • namestringrequired

          The workspace's name.

        • titlestringrequired

          The workspace's title.

    • Whether semantic search works on the endpoint's dataset. null when the connection doesn't query a dataset, or when semantic search is on but the dataset doesn't have embeddings enabled. It never affects ready: without it, the agent searches with GROQ only.

      Show child attributes
      • okbooleanrequired

        The check passed.

      • statusrequired

        The dataset's embeddings index status, if known.

        Show child attributes
        • string
      • Whether the project is within its embeddings usage limit, or null if it couldn't be checked.

        Show child attributes
        • boolean
      • activebooleanrequired

        Whether agents connecting now can use semantic search. On versions before v2026-11-03, ?embeddings=true forces the tool on for agents even when this is false.

      • Why semantic search isn't active: turnedOff when the dataset source has it off, datasetEmbeddingsNotReady while the dataset's embeddings are still being prepared, and usageLimitReached when the organization has no embeddings usage left. null when it is active.

        Show child attributes
        • string
          enum:"turnedOff", "datasetEmbeddingsNotReady", "usageLimitReached"
    • schemarequired

      Whether the studio's schema has document types the agent can query. null when the connection doesn't query a dataset.

      Show child attributes
      • okbooleanrequired

        The check passed.

      • documentTypesintegerrequired

        The number of document types the agent can query, after the endpoint's GROQ filter.

      • perspectivestringrequired

        The perspective agents query the dataset with, such as published or drafts.

    • Whether every knowledge base the connection serves exists and has been built. null when the connection doesn't serve knowledge bases.

      Show child attributes
      • okbooleanrequired

        The check passed.

      • resolvedarrayrequired

        The IDs of the knowledge bases the connection serves.

        Show child attributes
        items
        • string
    • accessrequired

      Whether your credentials can read the knowledge bases the connection serves. It never affects ready: agents connect with their own credentials, so check with the agent's token to know whether that agent can connect. null when the connection serves no knowledge bases that exist.

      Show child attributes
      • okbooleanrequired

        You can read every knowledge base.

conversations

Record agent conversations and their classifications for Insights.

Record a conversation

put/{apiVersion}/context/organizations/{organizationId}/conversations/{threadId}

Creates or updates the recorded conversation for one thread. threadId identifies the conversation within your organization, so saving with the same threadId updates the same conversation. Requires one of the sanity.knowledge-base.update, sanity.knowledge-base.entries.update, sanity.knowledge-base.issues.update, or sanity.knowledge-base.instructions.update grants on all knowledge bases in the organization, which the Context Editor role and higher have. Without it, the request returns 403 with code insightsWriteAccessDenied.

Each save replaces the stored messages. metadata, sharing, and the model fields change only when you include them. tokenUsage is cumulative: send the usage for one generation call, and the API adds it to the conversation total. Usage is added only when the save changes the messages, so retries don't count it twice.

To report a failure, set error on the message where it happened: the tool result for a failed tool call, or the assistant message for a turn that failed instead of answering. The Insights dashboard highlights conversations with a failed turn and counts failed tool calls separately, because agents often recover from them.

The last write for a thread wins, so retries are safe. sharing records whether you share telemetry with Sanity: metrics only, or full transcripts.

The request body can be at most 1 MiB. A larger body returns 413 with code payloadTooLarge.

Path parameters

  • threadIdstringrequired

    Your ID for the conversation thread, unique within your organization. Up to 200 characters. insights is reserved and returns 400.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03
  • organizationIdstringrequired

    The ID of the organization.

Request body application/json

  • messagesarrayrequired

    The full transcript so far, in order. It replaces the stored messages.

    Show child attributes
    items
    • rolestringrequired

      Who sent the message. user is the person talking to the agent, assistant is the agent, system is a system prompt, and tool is a tool call or tool result.

    • contentdefault: null

      The message text. null when the message has no text, such as a tool call.

      Show child attributes
      • string
    • toolNamedefault: null

      The name of the tool for a tool message. null on other messages.

      Show child attributes
      • string
    • toolTypedefault: null

      The kind of tool message. call is the agent calling the tool, and result is what the tool returned. null on other messages.

      Show child attributes
      • string
        enum:"call", "result"
    • errordefault: null

      Why this step failed, including any stack trace. Set it on the tool result for a failed tool call, or on the assistant message for a turn that failed instead of answering. null when the step succeeded.

      Show child attributes
      • string
  • The provider of the model the agent used. When absent, the stored value stays unchanged.

  • modelIdstring

    The ID of the model the agent used. When absent, the stored value stays unchanged.

  • Token usage for one generation call. The API adds it to the conversation total, but only when this save changes the messages.

    Show child attributes
  • metadataobject

    Up to 20 tags that describe the conversation. Well-known keys are mcpEndpoints (names of the MCP endpoints the conversation used), app, and environment. Add any other keys you need. Replaces the stored metadata. When absent, the stored value stays unchanged.

  • sharingobject

    Your choice to share conversation telemetry with Sanity. Replaces the stored setting. When absent, the stored value stays unchanged.

    Show child attributes
    • metricsboolean

      Whether to share classification metrics with Sanity: scores, sentiment, content gap counts, message counts and sizes, tool names, and model and token usage. Message content is not included.

    • Whether to share full conversation transcripts with Sanity. When true, the API also sets metrics to true.

    • contactstring

      How the Sanity team can reach you about your agent, such as an email address or a Discord handle.

Responses

200

A recorded agent conversation: its transcript, metadata, token usage, and classification.

  • idstringrequired

    The conversation ID, unique within the organization. It matches the _id of the conversation document in your document store.

  • threadIdstringrequired

    Your identifier for the conversation thread, unique within the organization. Saving with the same threadId updates the same conversation.

  • metadatarequired

    Tags that describe the conversation, such as mcpEndpoints, app, and environment. Filter on them in GROQ queries. null until a save includes metadata.

    Show child attributes
    • object

      Up to 20 tags that describe the conversation. Each value is a string or an array of strings. Well-known keys are mcpEndpoints (names of the MCP endpoints the conversation used), app, and environment. A string mcpEndpoints value is stored as a one-item array. Add any other keys you need and filter on them in GROQ queries.

  • startedAtstring (date-time)required

    When the API received the first save for this thread, as an ISO 8601 timestamp.

  • messagesUpdatedAtstring (date-time)required

    When the conversation was last saved, as an ISO 8601 timestamp.

  • messagesarrayrequired

    The conversation transcript, in order. Each save replaces it.

    Show child attributes
    items
    • rolestringrequired

      Who sent the message. user is the person talking to the agent, assistant is the agent, system is a system prompt, and tool is a tool call or tool result.

    • contentdefault: nullrequired

      The message text. null when the message has no text, such as a tool call.

      Show child attributes
      • string
    • toolNamedefault: nullrequired

      The name of the tool for a tool message. null on other messages.

      Show child attributes
      • string
    • toolTypedefault: nullrequired

      The kind of tool message. call is the agent calling the tool, and result is what the tool returned. null on other messages.

      Show child attributes
      • string
        enum:"call", "result"
    • errordefault: nullrequired

      Why this step failed, including any stack trace. Set it on the tool result for a failed tool call, or on the assistant message for a turn that failed instead of answering. null when the step succeeded.

      Show child attributes
      • string
    • timestampdefault: nullrequired

      When the API first received this message, as an ISO 8601 timestamp. The API sets it. Resending an unchanged message at the same position keeps its timestamp. null for messages recorded before timestamps existed.

      Show child attributes
      • string (date-time)
  • The provider of the model the agent used. null until a save includes modelProvider.

    Show child attributes
    • string
  • modelIdrequired

    The ID of the model the agent used. null until a save includes modelId.

    Show child attributes
    • string
  • tokenUsagerequired

    The running total of token usage for the conversation. null until a save includes tokenUsage.

    Show child attributes
  • coreMetricsrequired

    The latest classification result. null until you record one.

    Show child attributes
    • How well the agent resolved the user's needs, from 1 to 10.

    • sentimentstring

      The overall sentiment of the conversation.

    • Topics the agent couldn't answer because it lacked content.

      Show child attributes
      items
      • string
  • classifiedAtrequired

    When the latest classification result was recorded, as an ISO 8601 timestamp. The API sets it. null until you record a result.

    Show child attributes
    • string (date-time)
  • Why your classifier couldn't classify the conversation. null when no failure is recorded. Recording a result clears it.

    Show child attributes
    • string
  • sharingrequired

    Your choice to share conversation telemetry with Sanity. null until a save includes sharing.

    Show child attributes
    • metricsboolean

      Whether to share classification metrics with Sanity: scores, sentiment, content gap counts, message counts and sizes, tool names, and model and token usage. Message content is not included.

    • Whether to share full conversation transcripts with Sanity. When true, the API also sets metrics to true.

    • contactstring

      How the Sanity team can reach you about your agent, such as an email address or a Discord handle.

  • createdAtstring (date-time)required

    When the conversation was created, as an ISO 8601 timestamp.

  • updatedAtstring (date-time)required

    When the conversation was last changed, as an ISO 8601 timestamp.

Record a conversation classification

patch/{apiVersion}/context/organizations/{organizationId}/conversations/{threadId}

Records the classification your own model produced for one thread. Send exactly one of these fields:

  • coreMetrics: the classification result. The API sets classifiedAt and clears any recorded failure.
  • classificationError: why classification failed. Any earlier result stays unchanged.

Requires the same access as recording a conversation. The last write wins, so a new classification replaces the previous one. A thread with no recorded conversation returns 404 with code conversationNotFound.

Path parameters

  • threadIdstringrequired

    Your ID for the conversation thread, unique within your organization. Up to 200 characters. insights is reserved and returns 400.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03
  • organizationIdstringrequired

    The ID of the organization.

Request body application/json

  • The classification result. The API sets classifiedAt and clears any recorded classificationError.

    Show child attributes
    • successScoreintegerrequired

      How well the agent resolved the user's needs, as an integer from 1 to 10.

    • sentimentstringrequired

      The overall sentiment of the conversation.

    • contentGapsarrayrequired

      Topics the agent couldn't answer because it lacked content.

      Show child attributes
      items
      • string
  • Why your classifier couldn't classify the conversation. Any earlier classification result stays unchanged.

Responses

200

A recorded agent conversation: its transcript, metadata, token usage, and classification.

  • idstringrequired

    The conversation ID, unique within the organization. It matches the _id of the conversation document in your document store.

  • threadIdstringrequired

    Your identifier for the conversation thread, unique within the organization. Saving with the same threadId updates the same conversation.

  • metadatarequired

    Tags that describe the conversation, such as mcpEndpoints, app, and environment. Filter on them in GROQ queries. null until a save includes metadata.

    Show child attributes
    • object

      Up to 20 tags that describe the conversation. Each value is a string or an array of strings. Well-known keys are mcpEndpoints (names of the MCP endpoints the conversation used), app, and environment. A string mcpEndpoints value is stored as a one-item array. Add any other keys you need and filter on them in GROQ queries.

  • startedAtstring (date-time)required

    When the API received the first save for this thread, as an ISO 8601 timestamp.

  • messagesUpdatedAtstring (date-time)required

    When the conversation was last saved, as an ISO 8601 timestamp.

  • messagesarrayrequired

    The conversation transcript, in order. Each save replaces it.

    Show child attributes
    items
    • rolestringrequired

      Who sent the message. user is the person talking to the agent, assistant is the agent, system is a system prompt, and tool is a tool call or tool result.

    • contentdefault: nullrequired

      The message text. null when the message has no text, such as a tool call.

      Show child attributes
      • string
    • toolNamedefault: nullrequired

      The name of the tool for a tool message. null on other messages.

      Show child attributes
      • string
    • toolTypedefault: nullrequired

      The kind of tool message. call is the agent calling the tool, and result is what the tool returned. null on other messages.

      Show child attributes
      • string
        enum:"call", "result"
    • errordefault: nullrequired

      Why this step failed, including any stack trace. Set it on the tool result for a failed tool call, or on the assistant message for a turn that failed instead of answering. null when the step succeeded.

      Show child attributes
      • string
    • timestampdefault: nullrequired

      When the API first received this message, as an ISO 8601 timestamp. The API sets it. Resending an unchanged message at the same position keeps its timestamp. null for messages recorded before timestamps existed.

      Show child attributes
      • string (date-time)
  • The provider of the model the agent used. null until a save includes modelProvider.

    Show child attributes
    • string
  • modelIdrequired

    The ID of the model the agent used. null until a save includes modelId.

    Show child attributes
    • string
  • tokenUsagerequired

    The running total of token usage for the conversation. null until a save includes tokenUsage.

    Show child attributes
  • coreMetricsrequired

    The latest classification result. null until you record one.

    Show child attributes
    • How well the agent resolved the user's needs, from 1 to 10.

    • sentimentstring

      The overall sentiment of the conversation.

    • Topics the agent couldn't answer because it lacked content.

      Show child attributes
      items
      • string
  • classifiedAtrequired

    When the latest classification result was recorded, as an ISO 8601 timestamp. The API sets it. null until you record a result.

    Show child attributes
    • string (date-time)
  • Why your classifier couldn't classify the conversation. null when no failure is recorded. Recording a result clears it.

    Show child attributes
    • string
  • sharingrequired

    Your choice to share conversation telemetry with Sanity. null until a save includes sharing.

    Show child attributes
    • metricsboolean

      Whether to share classification metrics with Sanity: scores, sentiment, content gap counts, message counts and sizes, tool names, and model and token usage. Message content is not included.

    • Whether to share full conversation transcripts with Sanity. When true, the API also sets metrics to true.

    • contactstring

      How the Sanity team can reach you about your agent, such as an email address or a Discord handle.

  • createdAtstring (date-time)required

    When the conversation was created, as an ISO 8601 timestamp.

  • updatedAtstring (date-time)required

    When the conversation was last changed, as an ISO 8601 timestamp.

Delete a conversation

delete/{apiVersion}/context/organizations/{organizationId}/conversations/{threadId}

Deletes the recorded conversation for one thread, including its messages and classification. Requires the same access as recording a conversation.

Saving with the same threadId afterwards records a new conversation. A thread with no recorded conversation returns 404 with code conversationNotFound, including one you already deleted.

Path parameters

  • threadIdstringrequired

    Your ID for the conversation thread, unique within your organization. Up to 200 characters. insights is reserved and returns 400.

  • apiVersionstringrequired

    The API version: a date in the format vYYYY-MM-DD, or vX for the latest, unstable version. Use v2026-11-03: earlier versions keep behavior that has since changed.

    Example:v2026-11-03
  • organizationIdstringrequired

    The ID of the organization.

Responses

204

No content.

Sanity logosanity.ioAll Systems Operational© Sanity 2026
Change site theme