Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'doc/api/code_suggestions.md')
-rw-r--r--doc/api/code_suggestions.md81
1 files changed, 81 insertions, 0 deletions
diff --git a/doc/api/code_suggestions.md b/doc/api/code_suggestions.md
new file mode 100644
index 00000000000..8057686897f
--- /dev/null
+++ b/doc/api/code_suggestions.md
@@ -0,0 +1,81 @@
+---
+stage: Manage
+group: AI assisted
+info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
+---
+
+# Code Suggestions API
+
+Use the Code Suggestions API to access the Code Suggestions feature.
+
+## Create an access token
+
+> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/404427) in GitLab 16.1.
+
+Creates an access token to access Code Suggestions.
+
+```plaintext
+POST /code_suggestions/tokens
+```
+
+```shell
+curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/code_suggestions/tokens"
+```
+
+Example response:
+
+```json
+{
+ "access_token": "secret-access-token",
+ "expires_in": 3600,
+ "created_at": 1687865199
+}
+```
+
+## Generate code completions (Experiment)
+
+> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/415581) in GitLab 16.2 [with a flag](../administration/feature_flags.md) named `code_suggestions_completion_api`. Disabled by default. This feature is an Experiment.
+
+FLAG:
+On self-managed GitLab, by default this feature is not available.
+On GitLab.com, this feature is not available.
+This feature is not ready for production use.
+
+Use the AI abstraction layer to generate code completions.
+
+```plaintext
+POST /code_suggestions/completions
+```
+
+Requests to this endpoint are proxied directly to the [model gateway](https://gitlab.com/gitlab-org/modelops/applied-ml/code-suggestions/ai-assist#completions). The documentation for the endpoint is currently the SSoT for named parameters.
+
+Authentication to this endpoint requires both a GitLab access token and a Code Suggestions JWT. The access token is used to authenticate the user and the JWT is used to authenticate the request to the model gateway.
+
+```shell
+curl --header "Authorization: Bearer <YOUR_ACCESS_TOKEN>" --header "X-Gitlab-Oidc-Token: <TOKEN_GENERATED_FROM_TOKENS_ENDPOINT>" --data "<JSON_BODY>" https://gitlab.example.com/api/v4/code_suggestions/completions
+```
+
+Example body:
+
+The [model gateway](https://gitlab.com/gitlab-org/modelops/applied-ml/code-suggestions/ai-assist#completions) is the SSoT for parameters.
+
+Example response:
+
+```json
+{
+ "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"
+ }
+ ]
+}
+```