For code search integrations, use the streaming search API instead. It is purpose-built for consuming search results and is the same API used by the Sourcegraph UI.
Endpoint
query field (the GraphQL query string) and an optional variables field.
Authentication
- Access token
- OAuth token
- Sudo token
Generate a personal access token under Settings > Access tokens, then pass it in the
Authorization header:Example queries
Verify authentication
Search for code
Look up a repository
Read a file
API console
Sourcegraph ships with a built-in API console where you can write queries and browse the schema interactively.- Navigate to Settings > Debug console in your Sourcegraph instance, or visit
https://sourcegraph.example.com/debug/consoledirectly. - Click Docs on the right side of the console to browse the schema documentation.
- You can also use the Sourcegraph.com debug console to test against the latest API version.
Sourcegraph CLI
The src-cli provides a command-line interface to the GraphQL API. It reads your access token and instance URL from a config file or environment variables, handles JSON escaping, and lets you pipe multi-line queries easily.Query cost limits
To protect system stability, Sourcegraph enforces limits on GraphQL query complexity. These defaults can be adjusted in site configuration underrateLimits.
Use pagination where available to stay within the
graphQLMaxFieldCount limit when working with large data sets.