Endpoint
Authentication
Pass your access token or OAuth token in theAuthorization header.
- Access token
- OAuth token
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 anevent: line and a data: line. Events are separated by two newline characters (\n\n). The data: field is always JSON.
done event.
Event types
Example
This example runs a search against Sourcegraph.com (which allows unauthenticated queries for public code):Use cases
Exhaustive search over all repositories
To search all indexed repositories without a result limit, usecount:all and remove any repo: filters:
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
- Sourcegraph CLI (
src-cli):src search -stream "your query"— available at sourcegraph/src-cli - TypeScript/JavaScript: a community-maintained client for Node.js, browsers, and Deno is available at ziv/source-graph-stream-client
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.