Code Suggestions API
Use the Code Suggestions API to access the Code Suggestions feature.
Create an access token
Introduced in GitLab 16.1.
Creates an access token to access Code Suggestions.
POST /code_suggestions/tokens
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/code_suggestions/tokens"
Example response:
{
"access_token": "secret-access-token",
"expires_in": 3600,
"created_at": 1687865199
}
Generate code completions (EXPERIMENT)
- Introduced in GitLab 16.2 with a flag named
code_suggestions_completion_api
. Disabled by default. This feature is an Experiment.- Requirement to generate a JWT before calling this endpoint was removed in GitLab 16.3.
- Generally available in GitLab 16.8. Feature flag
code_suggestions_completion_api
removed.
FLAG:
On self-managed GitLab, by default this feature is not available. To make it available, an administrator can enable the feature flag named code_suggestions_completion_api
.
On GitLab.com, this feature is not available.
This feature is not ready for production use.
NOTE: This endpoint rate-limits each user to 60 requests per 1-minute window.
Use the AI abstraction layer to generate code completions.
POST /code_suggestions/completions
Requests to this endpoint are proxied directly to the model gateway. The documentation for the endpoint is currently the SSoT for named parameters.
curl --request POST \
--header "Authorization: Bearer <YOUR_ACCESS_TOKEN>" \
--data "<JSON_BODY>" \
--url "https://gitlab.example.com/api/v4/code_suggestions/completions"
Example body:
The model gateway is the SSoT for parameters.
Example response:
{
"id": "id",
"model": {
"engine": "vertex-ai",
"name": "code-gecko"
},
"object": "text_completion",
"created": 1688557841,
"choices": [
{
"text": "\n if self.is_running:\n self.speed += increment\n print(\"The car's speed is now",
"index": 0,
"finish_reason": "length"
}
]
}