Endpoint
Authentication
Pass your access token or OAuth token in theAuthorization header.
- Access token
- OAuth token
Query parameters
| Parameter | Required | Description |
|---|---|---|
q | Yes | A Sourcegraph search query. See search query syntax. |
v | No | Query syntax version. Use V3 (default and recommended). |
t | No | Pattern type: keyword, standard, or regexp. Only applied if q doesn’t already contain patternType:. Default: standard. |
display | No | Maximum number of matches to return. The backend continues searching and computing statistics after this limit. Default: no limit. |
cm | No | Enable chunk matches (true/false). Provides richer match context. Default: false. |
max-line-len | No | Truncate lines in ChunkMatch results to this length. Default: no limit. |
cl | No | Number of context lines around each match. Requires cm=true. Default: 1. |
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
| Event | Description |
|---|---|
matches | Search results. Each match can be of type content, path, commit, diff, symbol, or repo. |
progress | Aggregated statistics: match count, repository count, duration, and skipped reasons. |
filters | Suggested filters to narrow the search further. |
alert | Info, warning, or error messages from the search backend. |
done | Always the final event. Signals the stream is complete. |
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.