GitLab Duo Chat completions API
This API is used to generate responses for GitLab Duo Chat. This API is for internal use only.
Prerequisites:
- You must be a GitLab team member.
Generate Chat responses
{{< history >}}
-
Introduced in GitLab 16.7 with a flag named
access_rest_chat
. Disabled by default. This feature is internal-only. -
Added additional_context parameter in GitLab 17.4 with a flag named
duo_additional_context
. Disabled by default. This feature is internal-only. -
Enabled on GitLab.com and GitLab Self-Managed in GitLab 17.9 with a flag named
duo_additional_context
.-
Generally available in GitLab 18.0. Feature flag
duo_additional_context
removed in GitLab 18.0.
-
Generally available in GitLab 18.0. Feature flag
{{< /history >}}
POST /chat/completions
{{< alert type=”note” >}}
Requests to this endpoint are proxied to the AI gateway.
{{< /alert >}}
Supported attributes:
Attribute | Type | Required | Description |
---|---|---|---|
content
| string | Yes | Question sent to Chat. |
resource_type
| string | No | Type of resource that is sent with Chat question. |
resource_id
| string, integer | No | ID of the resource. Can be a resource ID (integer) or a commit hash (string). |
referer_url
| string | No | Referer URL. |
client_subscription_id
| string | No | Client Subscription ID. |
with_clean_history
| boolean | No | Indicates if we need to reset the history before and after the request. |
project_id
| integer | No | Project ID. Required if resource_type is a commit.
|
additional_context
| array | No | An array of additional context items for this chat request. See Context attributes for a list of parameters this attribute accepts. |
Context attributes
The context
attribute accepts a list of elements with the following attributes:
-
category
- The category of the context element. Valid values arefile
,merge_request
,issue
, orsnippet
. -
id
- The ID of the context element. -
content
- The content of the context element. The value depends on the category of the context element. -
metadata
- The optional additional metadata for this context element. The value depends on the category of the context element.
Example request:
curl --request POST \
--header "Authorization: Bearer <YOUR_ACCESS_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"content": "how to define class in ruby",
"additional_context": [
{
"category": "file",
"id": "main.rb",
"content": "class Foo\nend"
}
]
}' \
--url "https://gitlab.example.com/api/v4/chat/completions"
Example response:
"To define class in ruby..."