Skip to main content
The Sourcegraph streaming search API delivers search results and metadata as a stream of server-sent events (SSE). The Sourcegraph UI uses this API for all interactive searches. It provides shorter time-to-first-result compared to a single HTTP response and handles exhaustive searches returning large volumes of results without putting pressure on the backend.

Endpoint

Authentication

Pass your access token or OAuth token in the Authorization header.

Query parameters

The display parameter is different from the count: query filter. display limits what is returned to the client, while count: stops the search once that many matches are found.

Event stream format

The API responds with a stream of events following the server-sent events format. Each event has an event: line and a data: line. Events are separated by two newline characters (\n\n). The data: field is always JSON.
The stream always ends with a done event.

Event types

Example

This example runs a search against Sourcegraph.com (which allows unauthenticated queries for public code):
Sample response:

Use cases

Exhaustive search over all repositories

To search all indexed repositories without a result limit, use count:all and remove any repo: filters:
Or using the Sourcegraph CLI:

CI integration

The streaming API is well suited for CI checks that need to surface search results quickly — for example, scanning for secrets, deprecated APIs, or banned patterns across pull request diffs.

Client libraries

Although the streaming API follows the server-sent events format, Sourcegraph does not guarantee compatibility with generic SSE client libraries. For production use, write a purpose-built wrapper or use the src-cli.