Overview
Codeium supports an API for custom analytics in version. It allows querying for data from autocomplete, chat, and command, and a variety of filters, groupings, and aggregations. This article is for the SaaS version of codeium; see this article for the on-prem version.
Analytics API specification
We provide examples in curl; it can then be translated into HTTP requests in other languages.
curl -X POST --header "Content-Type: application/json" \
--data '{
"service_key": "<SERVICE_KEY>",
"group_name": "<GROUP_NAME>",
"query_requests": [
{
"data_source": "QUERY_DATA_SOURCE_<DATA_SOURCE>",
"selections": [
<LIST OF SELECTIONS>
],
"filters": [
<LIST OF FILTERS>
],
"aggregations": [
<LIST OF AGGREGATIONS>
],
}
]
}' \
https://server.codeium.com/api/v1/Analytics
DATA_SOURCE: select either USER_DATA, CHAT_DATA, or COMMAND_DATA depending on whether you are looking for autocomplete, chat, or command data.
SERVICE_KEY: The service key - an admin user can create a new one from https://codeium.com/team/team_settings
GROUP_NAME: The name of a group to filter on. This field is optional.
Schemas for selections, filters, aggregations, and orderings are in the following section, in JSON format. Example queries and for each of the three data sources, as well as query debugging tips, will be at the end of the document.
Schemas
Selections
Selections are required. Each selection corresponds to a value to be queried.
{
"field": "<FIELD_NAME>",
"name": "<NAME>",
"aggregation_function": "QUERY_AGGREGATION_<AGGREGATION_FUNCTION>"
}
FIELD_NAME: The field you wish to query. See the Available Fields section below.
NAME: An alias for the field. If not specified, will be the lowercase version of <AGGREGATION_FUNCTION>_<FIELD_NAME>, e.g. sum_num_acceptances. Must be distinct from all other field and aggregation names.
AGGREGATION_FUNCTION: should be one of UNSPECIFIED, COUNT, SUM, AVG, MAX, MIN. If "aggregation_function" is not provided, defaults to UNSPECIFIED.
Filters
Filters are used to narrow down the data to only contain elements that meet certain criteria. They are optional.
{
"name": "<NAME>",
"value": "<VALUE>",
"filter": "QUERY_FILTER_<FILTER>"
}
NAME: The name of the field you wish to filter. If the filtered item is the same as a Selection/Aggregation, this must be equal to the name of the field/aggregation.
VALUE: the value being compared.
FILTER: One of EQUAL, NOT_EQUAL, GREATER_THAN, LESS_THAN, GE (greater than or equal), LE (less than or equal).
Aggregations
Aggregations are used to split the data into groups based off a specified criteria. They are optional.
{
"field": <FIELD_NAME>,
"name": <NAME>
}
FIELD_NAME: The field you wish to query. See the Available Fields section.
NAME: An alias for the field. Must be distinct from all other field and aggregation names.
Available Fields
User Data
All data from the USER_DATA source is aggregated per user, per hour.
Field Name | Description | Valid Aggregations |
api_key | A hash of the user API key. | UNSPECIFIED, COUNT |
date | The UTC date of the autocompletion(s). | UNSPECIFIED, COUNT |
hour | The UTC hour of the autocompletions(s). | UNSPECIFIED, COUNT |
language | The programming language being used. | UNSPECIFIED, COUNT |
ide | The IDE that was being used. | UNSPECIFIED, COUNT |
version | The Codeium version used | UNSPECIFIED, COUNT |
num_acceptances | The number of times the user accepted an autocomplete. This occurs when the user writes some code, sees grey text, and presses tab. | SUM, MAX, MIN, AVG |
num_lines_accepted | Lines of code accepted from autocomplete. | SUM, MAX, MIN, AVG |
num_bytes_accepted | Bytes accepted from autocomplete. | SUM, MAX, MIN, AVG |
distinct_users | Distinct users. | UNSPECIFIED, COUNT |
distinct_developer_days | Distinct (users, day) tuples. | UNSPECIFIED, COUNT |
distinct_developer_hours | Distinct (users, hour of day) tuples. | UNSPECIFIED, COUNT |
pcw | Percent code written. Calculated as (number of codeium bytes generated) / (number of codeium bytes generated + number of user bytes generated). This metric can have high variance within single days or users, so we recommend aggregating over weeks for this. | UNSPECIFIED |
Chat Data
Note that all data provided in the chat data API are for the chat model responses, not the user questions.
Field Name | Description | Valid Aggregations |
api_key | A hash of the user API key | UNSPECIFIED, COUNT |
model_id | The chat model's ID, set during deployment time. | UNSPECIFIED, COUNT |
date | The UTC date of the chat response. | UNSPECIFIED, COUNT |
ide | The IDE that was being used | UNSPECIFIED, COUNT |
version | The Codeium version used | UNSPECIFIED, COUNT |
latest_intent_type |
Whether the model response is generated from a code lens or a regular chat. Regular chats will correspond to:
CHAT_INTENT_GENERIC
while code lenses will correspond to one of:
CHAT_INTENT_FUNCTION_EXPLAIN CHAT_INTENT_FUNCTION_DOCSTRING CHAT_INTENT_FUNCTION_REFACTOR CHAT_INTENT_CODE_BLOCK_EXPLAIN CHAT_INTENT_CODE_BLOCK_REFACTOR CHAT_INTENT_PROBLEM_EXPLAIN CHAT_INTENT_FUNCTION_UNIT_TESTS |
UNSPECIFIED, COUNT |
num_chats_received | Number of chats messages sent from Codeium to the user. | SUM, MAX, MIN, AVG |
chat_accepted | True if a code block was sent in Codeium's chat response, and the Thumbs up button is clicked. | SUM, COUNT |
chat_inserted_at_cursor | True if a code block was sent in Codeium's chat response, and the "Insert" button is clicked. | SUM, COUNT |
chat_applied | True if a code block was sent in Codeium's chat response, and the "Apply Diff" button is clicked. | SUM, COUNT |
chat_loc_used | Lines of code used, if a code block was sent in Codeium's chat, and any of the "Insert", "Copy", or "Apply Diff" buttons are pressed. | SUM, MAX, MIN, AVG |
Command Data
Note that the Command Data source contains all commands, including those which were declined. The "accepted" field can be used to filter for only accepted commands.
Field Name | Description | Valid Aggregations |
api_key | A hash of the user API key. | UNSPECIFIED, COUNT |
date |
The UTC date of the command. | UNSPECIFIED, COUNT |
timestamp | The UTC timestamp of the command. | UNSPECIFIED, COUNT |
language | The programming language being used. | UNSPECIFIED, COUNT |
ide | The IDE that was being used. | UNSPECIFIED, COUNT |
version | The Codeium version used | UNSPECIFIED, COUNT |
command_source |
The reason that the command was triggered. Valid values are,
COMMAND_REQUEST_SOURCE_LINE_HINT_CODE_LENS
COMMAND_REQUEST_SOURCE_DEFAULT corresponds to the typical command usage. |
UNSPECIFIED, COUNT |
provider_source |
Determines whether command was triggered in generation or edit mode. Valid values are, PROVIDER_SOURCE_COMMAND_GENERATE PROVIDER_SOURCE_COMMAND_EDIT |
UNSPECIFIED, COUNT |
lines_added | Number of lines of code added by the command. | SUM, MAX, MIN, AVG |
lines_removed | Number of lines of code removed by the command. | SUM, MAX, MIN, AVG |
bytes_added | Number of bytes added by the command. | SUM, MAX, MIN, AVG |
bytes_removed | Number of bytes removed by the command. | SUM, MAX, MIN, AVG |
selection_lines | Number of lines of code selected by the command. Should always be zero for generations. | SUM, MAX, MIN, AVG |
selection_bytes | Number of bytes selected by the command. Should always be zero for generations. | SUM, MAX, MIN, AVG |
accepted | Whether the command was accepted. | SUM, COUNT |
Examples
User Data
curl -X POST --header "Content-Type: application/json" \
--data '{
"service_key": SERVICE_KEY,
"query_requests": [
{
"data_source": "QUERY_DATA_SOURCE_USER_DATA",
"selections": [
{
"field": "pcw",
"name": "pcw"
}
],
"filters": [
{
"name": "hour",
"filter": "QUERY_FILTER_GE",
"value": "2024-01-01"
},
{
"name": "hour",
"filter": "QUERY_FILTER_LE",
"value": "2024-02-01"
}
]
}
]
}' \
https://<ENTERPRISE_PORTAL_URL>/api/v1/Analytics
This query calculates the overall Percent Code Written over the month of January 2024. Example response (JSON formatted for readability):
{
"queryResults": [
{
"responseItems": [
{
"item": {
pcw: 0.45
}
}
]
}
]
}
Chat Data
curl -X POST --header "Content-Type: application/json" \
--data '{
"service_key": SERVICE_KEY,
"query_requests": [
{
"data_source": "QUERY_DATA_SOURCE_CHAT_DATA",
"selections": [
{
"field": "chat_loc_used",
"name": "chat_loc_used",
"aggregation_function": "QUERY_AGGREGATION_SUM"
}
],
"filters": [
{
"name": "latest_intent_type",
"filter": "QUERY_FILTER_EQUAL",
"value": "CHAT_INTENT_FUNCTION_DOCSTRING"
}
],
"aggregations": [
{
"field": "ide",
"name": "ide"
}
]
}
]
}' \
https://<ENTERPRISE_PORTAL_URL>/api/v1/Analytics
This query shows the number of lines of code accepted from the "Generate Docstring" code lens, for all time, grouped by IDE.
Example response:
{
"queryResults": [
{
"responseItems": [
{
"item": {
"chat_loc_used": "74",
"ide": "jetbrains"
},
},
{
"item": {
"chat_loc_used":"41",
"ide":"vscode"
},
}
]
}
]
}
Command Data
curl -X POST --header "Content-Type: application/json" \
--data '{
"service_key": SERVICE_KEY,
"query_requests": [
{
"data_source": "QUERY_DATA_SOURCE_COMMAND_DATA",
"selections": [
{
"field": "lines_added",
"name": "lines_added",
"aggregation_function": "QUERY_AGGREGATION_SUM"
},
{
"field": "lines_removed",
"name": "lines_removed",
"aggregation_function": "QUERY_AGGREGATION_SUM"
}
],
"filters": [
{
"name": "provider_source",
"filter": "QUERY_FILTER_EQUAL",
"value": "PROVIDER_SOURCE_COMMAND_EDIT"
},
{
"name": "accepted",
"filter": "QUERY_FILTER_EQUAL",
"value": "true"
}
],
"aggregations": [
{
"field": "language",
"name": "language"
}
]
}
]
}' \
https://<ENTERPRISE_PORTAL_URL>/api/v1/Analytics
This query gets the number of lines added and removed from "edit" commands, grouped by programming language.
Example response:
{
"queryResults": [
{
"responseItems": [
{
"item": {
"language": "SHELL",
"lines_added": "5",
"lines_removed": "3"
}
},
{
"item": {
"language": "GO",
"lines_added": "31",
"lines_removed": "27"
}
},
{
"item": {
"language": "PYTHON",
"lines_added": "21",
"lines_removed": "5"
}
},
{
"item": {
"language": "UNSPECIFIED",
"lines_added": "91",
"lines_removed": "71"
}
},
{
"item": {
"language": "STARLARK",
"lines_added": "13",
"lines_removed": "1"
}
}
]
}
]
}
Query debugging
From 1.10.0 and on, invalid queries will return an error message. This section has some common error messages, what they mean, and how to debug the corresponding queries.
Error Message | Explanation |
at least one field or aggregation is required | Did not detect any selections or aggregations - make sure the query request contains at least one. |
invalid aggregation function for string type field ide: QUERY_AGGREGATION_SUM | One of the selections used an invalid aggregation function. In this case we tried to use SUM on the "ide" field, but it only supports COUNT and UNSPECIFIED |
invalid query table: QUERY_DATA_SOURCE_UNSPECIFIED | There is likely a typo in the data_source field, double check the spelling. |
all selection fields should have an aggregation function, or none of them should |
If there are multiple selection fields, either all should contain an aggregation_function, or none of them should. For example, this selection is invalid because num_acceptances is summed, but num_lines_accepted is not: "selections": [ Note: PCW is always considered aggregated. If no aggregation_function is explicitly chosen, it is considered unspecified. If you would like information about both of these fields, use two seperate queries. |
invalid aggregation function for string type field ide: QUERY_AGGREGATION_SUM | Not every field supports every aggregation function; see the available fields section for the matches. In this case, the query used a QUERY_AGGREGATION_SUM aggregation function with the "ide" field, which is invalid. |
tried to aggregate on a distinct field: distinct_developer_days. Consider aggregating on the non-distinct fields instead: [api_key date] |
Fields with the pattern "distinct_*" can not be in the aggregations section; the error suggests an alternative field(s) to aggregate on instead. So instead of: "aggregations": [ Try: "aggregations": [ |
duplicate field alias for selection/aggregation: num_acceptances | All selections and aggregations must have a different name. Keep in mind that if the name is not specified, by default it is set to <AGGREGATION_FUNCTION>_<FIELD_NAME>. |
invalid group name: GroupName | The group with the specified name was not found, double check the spelling. |