import os
from inceptionai import Inception
client = Inception(
api_key=os.environ.get("INCEPTION_API_KEY"), # defaults to this env var; can be omitted
)
edit_completion = client.edit.completions.create(
model="mercury-edit-2",
messages=[
{
"role": "user",
"content": "<|recently_viewed_code_snippets|>\n<|/recently_viewed_code_snippets|>\n<|edit_diff_history|>\n<|/edit_diff_history|>\n<|current_file_content|>\ndef greet(name):\n print(\"hi\")\n<|/current_file_content|>\n<|code_to_edit|>\ndef greet(name):\n print(\"hi\")<|cursor|>\n<|/code_to_edit|>"
}
],
)
print(edit_completion)import Inception from 'inceptionai';
const client = new Inception({
apiKey: process.env['INCEPTION_API_KEY'], // defaults to this env var; can be omitted
});
const editCompletion = await client.edit.completions.create({
model: 'mercury-edit-2',
messages: [
{
role: 'user',
content: '<|recently_viewed_code_snippets|>\n<|/recently_viewed_code_snippets|>\n<|edit_diff_history|>\n<|/edit_diff_history|>\n<|current_file_content|>\ndef greet(name):\n print("hi")\n<|/current_file_content|>\n<|code_to_edit|>\ndef greet(name):\n print("hi")<|cursor|>\n<|/code_to_edit|>'
}
]
});
console.log(editCompletion);curl --request POST \
--url https://api.inceptionlabs.ai/v1/edit/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "mercury-edit-2",
"messages": [
{
"role": "user",
"content": "<|recently_viewed_code_snippets|>\n<|/recently_viewed_code_snippets|>\n<|edit_diff_history|>\n<|/edit_diff_history|>\n<|current_file_content|>\ndef greet(name):\n print(\"hi\")\n<|/current_file_content|>\n<|code_to_edit|>\ndef greet(name):\n print(\"hi\")<|cursor|>\n<|/code_to_edit|>"
}
]
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'mercury-edit-2',
messages: [
{
role: 'user',
content: '<|recently_viewed_code_snippets|>\n<|/recently_viewed_code_snippets|>\n<|edit_diff_history|>\n<|/edit_diff_history|>\n<|current_file_content|>\ndef greet(name):\n print("hi")\n<|/current_file_content|>\n<|code_to_edit|>\ndef greet(name):\n print("hi")<|cursor|>\n<|/code_to_edit|>'
}
]
})
};
fetch('https://api.inceptionlabs.ai/v1/edit/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.inceptionlabs.ai/v1/edit/completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'mercury-edit-2',
'messages' => [
[
'role' => 'user',
'content' => '<|recently_viewed_code_snippets|>
<|/recently_viewed_code_snippets|>
<|edit_diff_history|>
<|/edit_diff_history|>
<|current_file_content|>
def greet(name):
print("hi")
<|/current_file_content|>
<|code_to_edit|>
def greet(name):
print("hi")<|cursor|>
<|/code_to_edit|>'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.inceptionlabs.ai/v1/edit/completions"
payload := strings.NewReader("{\n \"model\": \"mercury-edit-2\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<|recently_viewed_code_snippets|>\\n<|/recently_viewed_code_snippets|>\\n<|edit_diff_history|>\\n<|/edit_diff_history|>\\n<|current_file_content|>\\ndef greet(name):\\n print(\\\"hi\\\")\\n<|/current_file_content|>\\n<|code_to_edit|>\\ndef greet(name):\\n print(\\\"hi\\\")<|cursor|>\\n<|/code_to_edit|>\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.inceptionlabs.ai/v1/edit/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"mercury-edit-2\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<|recently_viewed_code_snippets|>\\n<|/recently_viewed_code_snippets|>\\n<|edit_diff_history|>\\n<|/edit_diff_history|>\\n<|current_file_content|>\\ndef greet(name):\\n print(\\\"hi\\\")\\n<|/current_file_content|>\\n<|code_to_edit|>\\ndef greet(name):\\n print(\\\"hi\\\")<|cursor|>\\n<|/code_to_edit|>\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.inceptionlabs.ai/v1/edit/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"mercury-edit-2\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<|recently_viewed_code_snippets|>\\n<|/recently_viewed_code_snippets|>\\n<|edit_diff_history|>\\n<|/edit_diff_history|>\\n<|current_file_content|>\\ndef greet(name):\\n print(\\\"hi\\\")\\n<|/current_file_content|>\\n<|code_to_edit|>\\ndef greet(name):\\n print(\\\"hi\\\")<|cursor|>\\n<|/code_to_edit|>\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "cmpl-7a2b3c4d5e",
"object": "edit.completion",
"created": 1745798400,
"model": "mercury-edit-2",
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": "def greet(name):\n print(f\"hi {name}\")\n"
}
}
],
"usage": {
"prompt_tokens": 156,
"completion_tokens": 18,
"total_tokens": 174,
"reasoning_tokens": 0,
"cached_input_tokens": 0
}
}{
"error": {
"message": "You exceeded the maximum context length for this model of 128000. Please reduce the length of the messages or completion.",
"type": "invalid_request_error",
"param": "messages",
"code": "context_length_exceeded"
}
}{
"error": {
"message": "Incorrect API key provided",
"type": "authentication_error",
"param": null,
"code": "invalid_api_key"
}
}{
"error": {
"message": "Account is inactive",
"type": "account_error",
"param": null,
"code": "account_error"
}
}{
"error": {
"message": "model `jupyter-2` not found",
"type": "invalid_request_error",
"param": "model",
"code": "model_not_found"
}
}{
"error": {
"message": "Rate limit exceeded. Please try again later.",
"type": "rate_limit_error",
"param": null,
"code": "rate_limit_reached"
}
}{
"error": {
"message": "The server had an error while processing your request.",
"type": "server_error",
"param": null,
"code": "server_error"
}
}Create a code edit completion
Generate an edit to a code region given the surrounding context. The request must contain a single user message whose content includes the required edit prompt tags (e.g. <|code_to_edit|>, <|cursor|>, <|current_file_content|>). Returns an EditCompletion object. Streaming and tool calling are not supported on this endpoint.
import os
from inceptionai import Inception
client = Inception(
api_key=os.environ.get("INCEPTION_API_KEY"), # defaults to this env var; can be omitted
)
edit_completion = client.edit.completions.create(
model="mercury-edit-2",
messages=[
{
"role": "user",
"content": "<|recently_viewed_code_snippets|>\n<|/recently_viewed_code_snippets|>\n<|edit_diff_history|>\n<|/edit_diff_history|>\n<|current_file_content|>\ndef greet(name):\n print(\"hi\")\n<|/current_file_content|>\n<|code_to_edit|>\ndef greet(name):\n print(\"hi\")<|cursor|>\n<|/code_to_edit|>"
}
],
)
print(edit_completion)import Inception from 'inceptionai';
const client = new Inception({
apiKey: process.env['INCEPTION_API_KEY'], // defaults to this env var; can be omitted
});
const editCompletion = await client.edit.completions.create({
model: 'mercury-edit-2',
messages: [
{
role: 'user',
content: '<|recently_viewed_code_snippets|>\n<|/recently_viewed_code_snippets|>\n<|edit_diff_history|>\n<|/edit_diff_history|>\n<|current_file_content|>\ndef greet(name):\n print("hi")\n<|/current_file_content|>\n<|code_to_edit|>\ndef greet(name):\n print("hi")<|cursor|>\n<|/code_to_edit|>'
}
]
});
console.log(editCompletion);curl --request POST \
--url https://api.inceptionlabs.ai/v1/edit/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "mercury-edit-2",
"messages": [
{
"role": "user",
"content": "<|recently_viewed_code_snippets|>\n<|/recently_viewed_code_snippets|>\n<|edit_diff_history|>\n<|/edit_diff_history|>\n<|current_file_content|>\ndef greet(name):\n print(\"hi\")\n<|/current_file_content|>\n<|code_to_edit|>\ndef greet(name):\n print(\"hi\")<|cursor|>\n<|/code_to_edit|>"
}
]
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'mercury-edit-2',
messages: [
{
role: 'user',
content: '<|recently_viewed_code_snippets|>\n<|/recently_viewed_code_snippets|>\n<|edit_diff_history|>\n<|/edit_diff_history|>\n<|current_file_content|>\ndef greet(name):\n print("hi")\n<|/current_file_content|>\n<|code_to_edit|>\ndef greet(name):\n print("hi")<|cursor|>\n<|/code_to_edit|>'
}
]
})
};
fetch('https://api.inceptionlabs.ai/v1/edit/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.inceptionlabs.ai/v1/edit/completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'mercury-edit-2',
'messages' => [
[
'role' => 'user',
'content' => '<|recently_viewed_code_snippets|>
<|/recently_viewed_code_snippets|>
<|edit_diff_history|>
<|/edit_diff_history|>
<|current_file_content|>
def greet(name):
print("hi")
<|/current_file_content|>
<|code_to_edit|>
def greet(name):
print("hi")<|cursor|>
<|/code_to_edit|>'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.inceptionlabs.ai/v1/edit/completions"
payload := strings.NewReader("{\n \"model\": \"mercury-edit-2\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<|recently_viewed_code_snippets|>\\n<|/recently_viewed_code_snippets|>\\n<|edit_diff_history|>\\n<|/edit_diff_history|>\\n<|current_file_content|>\\ndef greet(name):\\n print(\\\"hi\\\")\\n<|/current_file_content|>\\n<|code_to_edit|>\\ndef greet(name):\\n print(\\\"hi\\\")<|cursor|>\\n<|/code_to_edit|>\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.inceptionlabs.ai/v1/edit/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"mercury-edit-2\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<|recently_viewed_code_snippets|>\\n<|/recently_viewed_code_snippets|>\\n<|edit_diff_history|>\\n<|/edit_diff_history|>\\n<|current_file_content|>\\ndef greet(name):\\n print(\\\"hi\\\")\\n<|/current_file_content|>\\n<|code_to_edit|>\\ndef greet(name):\\n print(\\\"hi\\\")<|cursor|>\\n<|/code_to_edit|>\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.inceptionlabs.ai/v1/edit/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"mercury-edit-2\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<|recently_viewed_code_snippets|>\\n<|/recently_viewed_code_snippets|>\\n<|edit_diff_history|>\\n<|/edit_diff_history|>\\n<|current_file_content|>\\ndef greet(name):\\n print(\\\"hi\\\")\\n<|/current_file_content|>\\n<|code_to_edit|>\\ndef greet(name):\\n print(\\\"hi\\\")<|cursor|>\\n<|/code_to_edit|>\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "cmpl-7a2b3c4d5e",
"object": "edit.completion",
"created": 1745798400,
"model": "mercury-edit-2",
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": "def greet(name):\n print(f\"hi {name}\")\n"
}
}
],
"usage": {
"prompt_tokens": 156,
"completion_tokens": 18,
"total_tokens": 174,
"reasoning_tokens": 0,
"cached_input_tokens": 0
}
}{
"error": {
"message": "You exceeded the maximum context length for this model of 128000. Please reduce the length of the messages or completion.",
"type": "invalid_request_error",
"param": "messages",
"code": "context_length_exceeded"
}
}{
"error": {
"message": "Incorrect API key provided",
"type": "authentication_error",
"param": null,
"code": "invalid_api_key"
}
}{
"error": {
"message": "Account is inactive",
"type": "account_error",
"param": null,
"code": "account_error"
}
}{
"error": {
"message": "model `jupyter-2` not found",
"type": "invalid_request_error",
"param": "model",
"code": "model_not_found"
}
}{
"error": {
"message": "Rate limit exceeded. Please try again later.",
"type": "rate_limit_error",
"param": null,
"code": "rate_limit_reached"
}
}{
"error": {
"message": "The server had an error while processing your request.",
"type": "server_error",
"param": null,
"code": "server_error"
}
}Authorizations
API key provided as a Bearer token: Authorization: Bearer <api_key>. Get an API key at https://platform.inceptionlabs.ai.
Body
Show child attributes
Show child attributes
The model to use for the edit completion.
Maximum number of tokens to generate.
1 <= x <= 8192What sampling temperature to use, between 0 and 2. Higher values make the output more random; lower values make it more focused and deterministic.
0 <= x <= 2Float that controls the cumulative probability of the top tokens to consider.
0 <= x <= 1Number between -2 and 2. Positive values penalize tokens based on whether they have appeared in the text so far, increasing the model's likelihood to talk about new topics.
-2 <= x <= 2Response
Successful Response
Was this page helpful?