Skip to main content

Code graph API

This page documents the 15 gateway endpoints tagged code graph in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.

MethodPathSummary
GET/code_graph/credentialsList the credentials bound for code indexing
POST/code_graph/credentials/bindAllow one tenant to index with a stored credential
POST/code_graph/repos/connectConnect a repository for indexing
GET/code_graph/reposList the connected repositories
GET/code_graph/repos/{repo_id}/runsList the index runs of a repository
POST/code_graph/repos/{repo_id}/reindexIndex a repository again
POST/code_graph/repos/{repo_id}/settingsTurn permission mirroring on or off for a repository
POST/code_graph/repos/{repo_id}/webhookRotate the webhook of a repository
POST/code_graph/repos/{repo_id}/deleteDisconnect a repository and delete its index
GET/code_graph/appShow the code graph GitHub App status
POST/code_graph/app/installStart a code graph GitHub App install
POST/code_graph/app/install/completeFinish a code graph GitHub App install
POST/code_graph/webhooks/appReceive a code graph GitHub App webhook
POST/code_graph/webhooks/repo/{webhook_id}Receive a code graph GitHub repository webhook
POST/code_graph/webhooks/gitlab/{webhook_id}Receive a code graph GitLab project webhook

Endpoints​

GET /code_graph/credentials​

List the credentials bound for code indexing

List the stored source control credentials bound to a tenant for indexing, so you know which credential_name a repository connection can use. Secrets are never returned. A proxy admin, an admin viewer, a user whose role grants a code graph permission, or a team admin who passes team_id may call it. Nothing is changed

Parameters:

NameInTypeRequiredDescription
tenant_idquerystring or nullNo
team_idquerystring or nullNo

Example request:

curl -X GET "http://localhost:4000/code_graph/credentials" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json CodeGraphCredentialList
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The license does not include the code graph, or the caller's role or team does not allow thisapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
503The code graph database is not set up on this gatewayapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
credentialsarray of CodeGraphCredentialYesCredentials

POST /code_graph/credentials/bind​

Allow one tenant to index with a stored credential

Bind a stored GitHub personal access token or GitLab access token credential to the one tenant allowed to index repositories with it. Without tenant_id it is bound to the caller's own organization, or default for callers without one. A proxy admin or a user whose role grants code_graph.manage may call it, team admins may not. The binding is written to the audit log

Request body (application/json, schema CodeGraphCredentialBindRequest):

FieldTypeRequiredDescription
tenant_idstring or nullNoTenant Id
credential_namestringYesCredential Name

Example request:

curl -X POST "http://localhost:4000/code_graph/credentials/bind" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"tenant_id": "default",
"credential_name": "repo-indexer"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json CodeGraphCredentialBound
400The named credential is not a stored source control tokenapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The license does not include the code graph, or the caller's role or team does not allow thisapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
503The code graph database is not set up on this gatewayapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
tenant_idstringYesTenant Id
credential_namestringYesCredential Name

POST /code_graph/repos/connect​

Connect a repository for indexing

Connect a GitHub repository or GitLab project for indexing. A team admin can connect a repository their team will own. The connecting user and the tenant's bound credential must both be able to read it upstream, and for GitLab the user must be an active member of the project with at least the Reporter role. The first index run is queued at once, and the webhook secret in the answer is shown only this one time. A proxy admin, a user whose role grants code_graph.manage, or a team admin for their own team may call it. The connection is written to the audit log

Request body (application/json, schema CodeGraphConnectRequest):

FieldTypeRequiredDescription
tenant_idstring or nullNoTenant Id
team_idstring or nullNoTeam Id
providerenum: "jira", "gitlab"NoProvider
full_namestringYesFull Name
external_repo_idstringYesExternal Repo Id
default_branchstringYesDefault Branch
credential_namestringYesCredential Name
owner_team_idstring or nullNoOwner Team Id
user_token_server_idstringYesUser Token Server Id

Example request:

curl -X POST "http://localhost:4000/code_graph/repos/connect" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"full_name": "examplecorp/payments",
"external_repo_id": "123456789",
"default_branch": "main",
"credential_name": "repo-indexer",
"owner_team_id": "payments-team",
"user_token_server_id": "source-mcp"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json CodeGraphRepoConnected
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The license does not include the code graph, or the caller's role or team does not allow thisapplication/json ErrorDetail
409The repository is already connected in this tenantapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
503The code graph database is not set up on this gatewayapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
repoCodeGraphRepoYes
run_idstringYesRun Id
webhookCodeGraphWebhook or nullYes

GET /code_graph/repos​

List the connected repositories

List the repositories connected in a tenant with their index status, or the ones a team owns when a team admin asks with team_id. A proxy admin, an admin viewer, a user whose role grants a code graph permission, or a team admin may call it. Nothing is changed

Parameters:

NameInTypeRequiredDescription
tenant_idquerystring or nullNo
team_idquerystring or nullNo

Example request:

curl -X GET "http://localhost:4000/code_graph/repos" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json CodeGraphRepoList
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The license does not include the code graph, or the caller's role or team does not allow thisapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
503The code graph database is not set up on this gatewayapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
reposarray of CodeGraphRepoYesRepos

GET /code_graph/repos/{repo_id}/runs​

List the index runs of a repository

List the latest index runs of one repository, newest first, with how many files each one read and changed and the error of a failed run. A proxy admin, an admin viewer, a user whose role grants a code graph permission, or the admin of the team that owns the repository may call it. Nothing is changed

Parameters:

NameInTypeRequiredDescription
repo_idpathstringYes
tenant_idquerystring or nullNo
team_idquerystring or nullNo

Example request:

curl -X GET "http://localhost:4000/code_graph/repos/repo_id-123/runs" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json CodeGraphRunList
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The license does not include the code graph, or the caller's role or team does not allow thisapplication/json ErrorDetail
404No connected repository has that id in the caller's scopeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
503The code graph database is not set up on this gatewayapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
runsarray of CodeGraphRunYesRuns

POST /code_graph/repos/{repo_id}/reindex​

Index a repository again

Queue an index run for a connected repository. A run already waiting is started now instead. A proxy admin, a user whose role grants code_graph.reindex or code_graph.manage, or the admin of the owning team may call it. The request is written to the audit log

Parameters:

NameInTypeRequiredDescription
repo_idpathstringYes

Request body (application/json, schema CodeGraphRepoAction):

FieldTypeRequiredDescription
tenant_idstring or nullNoTenant Id
team_idstring or nullNoTeam Id

Example request:

curl -X POST "http://localhost:4000/code_graph/repos/repo_id-123/reindex" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"team_id": "payments-team"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json CodeGraphRunQueued
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The license does not include the code graph, or the caller's role or team does not allow thisapplication/json ErrorDetail
404No connected repository has that id in the caller's scopeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
503The code graph database is not set up on this gatewayapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
repo_idstringYesRepo Id
run_idstringYesRun Id

POST /code_graph/repos/{repo_id}/settings​

Turn permission mirroring on or off for a repository

Turn upstream permission mirroring on or off. With it on, a caller only sees the repository while their own GitHub or GitLab identity, from the per-user OAuth token of the named MCP server, can read it. With it off, anyone granted the repository through a team or key sees it. A proxy admin, a user whose role grants code_graph.manage, or the admin of the owning team may call it. The change is written to the audit log with the previous and the new setting

Parameters:

NameInTypeRequiredDescription
repo_idpathstringYes

Request body (application/json, schema CodeGraphRepoSettings):

FieldTypeRequiredDescription
tenant_idstring or nullNoTenant Id
team_idstring or nullNoTeam Id
mirror_source_permissionsbooleanYesMirror Source Permissions
acl_server_idstring or nullNoAcl Server Id

Example request:

curl -X POST "http://localhost:4000/code_graph/repos/repo_id-123/settings" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"mirror_source_permissions": true,
"acl_server_id": "repo-acl-mcp"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json CodeGraphRepo
400Mirroring was turned on without the MCP server to check access withapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The license does not include the code graph, or the caller's role or team does not allow thisapplication/json ErrorDetail
404No connected repository has that id in the caller's scopeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
503The code graph database is not set up on this gatewayapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
repo_idstringYesRepo Id
tenant_idstringYesTenant Id
providerstringYesProvider
full_namestringYesFull Name
default_branchstringYesDefault Branch
owner_team_idstring or nullYesOwner Team Id
statusstringYesStatus
last_indexed_shastring or nullYesLast Indexed Sha
last_errorstring or nullYesLast Error
webhook_pathstring or nullYesWebhook Path
mirror_source_permissionsbooleanYesMirror Source Permissions
acl_server_idstring or nullYesAcl Server Id
last_event_atstring or nullYesLast Event At

POST /code_graph/repos/{repo_id}/webhook​

Rotate the webhook of a repository

Give the repository a new webhook path and secret. The old ones stop working, and the secret is only shown in this response, so update the webhook at the source control host right away. A proxy admin, a user whose role grants code_graph.manage, or the admin of the owning team may call it. The rotation is written to the audit log

Parameters:

NameInTypeRequiredDescription
repo_idpathstringYes

Request body (application/json, schema CodeGraphRepoAction):

FieldTypeRequiredDescription
tenant_idstring or nullNoTenant Id
team_idstring or nullNoTeam Id

Example request:

curl -X POST "http://localhost:4000/code_graph/repos/repo_id-123/webhook" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"team_id": "payments-team"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json CodeGraphWebhook
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The license does not include the code graph, or the caller's role or team does not allow thisapplication/json ErrorDetail
404No connected repository has that id in the caller's scopeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
503The code graph is not configured, or no salt key is set to sign webhooksapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
pathstringYesPath
secretstringYesSecret

POST /code_graph/repos/{repo_id}/delete​

Disconnect a repository and delete its index

Disconnect a repository and delete everything indexed from it. This cannot be undone, connect the repository again to rebuild the index. A proxy admin, a user whose role grants code_graph.manage, or the admin of the owning team may call it. The deletion is written to the audit log

Parameters:

NameInTypeRequiredDescription
repo_idpathstringYes

Request body (application/json, schema CodeGraphRepoAction):

FieldTypeRequiredDescription
tenant_idstring or nullNoTenant Id
team_idstring or nullNoTeam Id

Example request:

curl -X POST "http://localhost:4000/code_graph/repos/repo_id-123/delete" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"team_id": "payments-team"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json CodeGraphRepoDeleted
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The license does not include the code graph, or the caller's role or team does not allow thisapplication/json ErrorDetail
404No connected repository has that id in the caller's scopeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
503The code graph database is not set up on this gatewayapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
repo_idstringYesRepo Id
deletedbooleanYesDeleted

GET /code_graph/app​

Show the code graph GitHub App status

Shows whether a GitHub App is set up for the code graph, the gateway path that receives its webhooks, and which actions the caller may take: connect repositories, queue index runs, install the App and bind credentials. The Admin UI reads it to decide which buttons to show. Any caller with read access to the tenant or team may call it. Nothing changes.

Parameters:

NameInTypeRequiredDescription
tenant_idquerystring or nullNo
team_idquerystring or nullNo

Example request:

curl -X GET "http://localhost:4000/code_graph/app" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Whether the App is set up and what the caller may do with itapplication/json CodeGraphApp
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The license does not include the code graph, or the caller's role or team does not allow thisapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
503The code graph database is not set up on this gatewayapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
configuredbooleanYesConfigured
slugstring or nullYesSlug
webhook_pathstringYesWebhook Path
can_managebooleanYesCan Manage
can_reindexbooleanYesCan Reindex
can_installbooleanYesCan Install
can_bind_credentialsbooleanYesCan Bind Credentials

POST /code_graph/app/install​

Start a code graph GitHub App install

Starts installing the code graph GitHub App for a tenant. Returns the upstream service link to open; the upstream service sends the user back to the Admin UI with a sealed state that only the same user can complete within ten minutes. Only a signed-in user who manages the whole tenant may call it (team admins cannot). Nothing is stored yet.

Request body (application/json, schema CodeGraphInstallStart):

FieldTypeRequiredDescription
tenant_idstring or nullNoTenant Id

Example request:

curl -X POST "http://localhost:4000/code_graph/app/install" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"tenant_id": "tenant-acme"
}'

Responses:

StatusDescriptionBody
200The link to open on the upstream service and how long it stays validapplication/json CodeGraphInstallLink
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller cannot manage the whole tenant or is not a signed-in userapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
503No GitHub App is configured, or install links cannot be sealed on this gatewayapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
install_urlstringYesInstall Url
expires_in_secondsintegerYesExpires In Seconds

POST /code_graph/app/install/complete​

Finish a code graph GitHub App install

Finishes a code graph GitHub App install that the same user started. The installation is bound to the tenant only when the upstream service confirms, with the user's own sign-in code, that this user can see it, so nobody can claim another organization's installation. Only a signed-in user who manages the whole tenant may call it. On success the installation becomes a credential the tenant's repositories can use, and an audit row is written.

Request body (application/json, schema CodeGraphInstallComplete):

FieldTypeRequiredDescription
statestringYesState
installation_idstringYesInstallation Id
codestringYesCode

Example request:

curl -X POST "http://localhost:4000/code_graph/app/install/complete" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"state": "eyJ...",
"installation_id": "12345678",
"code": "example-oauth-code"
}'

Responses:

StatusDescriptionBody
200The installation is now bound to the tenantapplication/json CodeGraphInstallationBound
400The install link expired, could not be read or was started by someone elseapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller cannot manage the tenant, or the upstream service did not confirm the user can see the installationapplication/json ErrorDetail
409The installation already belongs to another tenantapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
502The upstream service did not answer the installation lookupapplication/json ErrorDetail
503No GitHub App is configured, or install links cannot be sealed on this gatewayapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
tenant_idstringYesTenant Id
installation_idstringYesInstallation Id
credential_namestringYesCredential Name

POST /code_graph/webhooks/app​

Receive a code graph GitHub App webhook

Keeps the code graph up to date when code changes. The upstream service calls this, not people: point the GitHub App's webhook URL here. No gateway key is needed, instead the body must be signed with the App's webhook secret in the X-Hub-Signature-256 header, and X-GitHub-Delivery must carry the delivery id.

A push to a connected repository's default branch queues one index run (several quick pushes share one run). A removed installation or repository makes the affected repositories unreadable until access comes back, and an audit row records it under the system:code_graph actor. A delivery the upstream service sends twice is answered duplicate and changes nothing. The answer is always 202 with the outcome, a bad signature answers 401 and an unreadable payload 400.

Parameters:

NameInTypeRequiredDescription
X-GitHub-DeliveryheaderstringYes
X-Hub-Signature-256headerstring or nullNo
X-GitHub-Eventheaderstring or nullNo

Request body (application/json, object):

Example request:

curl -X POST "http://localhost:4000/code_graph/webhooks/app" \
-H "Content-Type: application/json" \
-d '{
"ref": "refs/heads/main",
"after": "0000000000000000000000000000000000000001",
"repository": {
"id": 123456
},
"installation": {
"id": 7654321
}
}'

Responses:

StatusDescriptionBody
202Successful Responseapplication/json CodeGraphWebhookReceipt
400The payload or its delivery id could not be readapplication/json ErrorDetail
401The X-Hub-Signature-256 header does not match the App's webhook secretapplication/json ErrorDetail
403The license does not include the code graph, or the caller's role or team does not allow thisapplication/json ErrorDetail
413The body is larger than 5 MBapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
503The code graph database is not set up on this gatewayapplication/json ErrorDetail

POST /code_graph/webhooks/repo/{webhook_id}​

Receive a code graph GitHub repository webhook

Keeps the code graph up to date for a repository connected with a personal access token. The upstream service calls this: the repository's webhook points at this URL, including the webhook_id shown when the repository was connected. No gateway key is needed, instead the body must be signed in X-Hub-Signature-256 with the secret shown when the repository was connected or its webhook rotated.

A push to the default branch queues one index run (several quick pushes share one run), any other event is answered ignored, and a repeated delivery duplicate. A bad signature answers 401 and an unreadable payload 400.

Parameters:

NameInTypeRequiredDescription
webhook_idpathstringYes
X-GitHub-DeliveryheaderstringYes
X-Hub-Signature-256headerstring or nullNo
X-GitHub-Eventheaderstring or nullNo

Request body (application/json, object):

Example request:

curl -X POST "http://localhost:4000/code_graph/webhooks/repo/webhook_id-123" \
-H "Content-Type: application/json" \
-d '{
"ref": "refs/heads/main",
"after": "0000000000000000000000000000000000000001",
"repository": {
"id": 123456
},
"installation": {
"id": 7654321
}
}'

Responses:

StatusDescriptionBody
202Successful Responseapplication/json CodeGraphWebhookReceipt
400The payload or its delivery id could not be readapplication/json ErrorDetail
401The X-Hub-Signature-256 header does not match this webhook's secretapplication/json ErrorDetail
403The license does not include the code graph, or the caller's role or team does not allow thisapplication/json ErrorDetail
413The body is larger than 5 MBapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
503The code graph database is not set up on this gatewayapplication/json ErrorDetail

POST /code_graph/webhooks/gitlab/{webhook_id}​

Receive a code graph GitLab project webhook

Keeps the code graph up to date for a connected GitLab project. GitLab calls this: the project's webhook points at this URL, including the webhook_id shown when the project was connected. No gateway key is needed, instead the X-Gitlab-Token header must equal the secret token shown when the project was connected or its webhook rotated, and Idempotency-Key or X-Gitlab-Event-UUID must carry the delivery id.

A push to the default branch queues one index run (several quick pushes share one run), any other event is answered ignored, and a repeated delivery duplicate. A wrong token answers 401, and a missing delivery id or an unreadable payload 400.

Parameters:

NameInTypeRequiredDescription
webhook_idpathstringYes
X-Gitlab-Tokenheaderstring or nullNo
X-Gitlab-Eventheaderstring or nullNo
X-Gitlab-Event-UUIDheaderstring or nullNo
Idempotency-Keyheaderstring or nullNo

Request body (application/json, object):

FieldTypeRequiredDescription
object_kind"push"YesObject Kind
refstringYesRef
afterstringYesAfter
project_idintegerYesProject Id

Example request:

curl -X POST "http://localhost:4000/code_graph/webhooks/gitlab/webhook_id-123" \
-H "Content-Type: application/json" \
-d '{
"object_kind": "push",
"ref": "refs/heads/main",
"after": "0000000000000000000000000000000000000001",
"project_id": 42
}'

Responses:

StatusDescriptionBody
202Successful Responseapplication/json CodeGraphWebhookReceipt
400The payload or its delivery id could not be readapplication/json ErrorDetail
401The X-Gitlab-Token header does not match this webhook's secret tokenapplication/json ErrorDetail
403The license does not include the code graph, or the caller's role or team does not allow thisapplication/json ErrorDetail
413The body is larger than 5 MBapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
503The code graph database is not set up on this gatewayapplication/json ErrorDetail