Python
import os
from inceptionai import Inception
client = Inception(
api_key=os.environ.get("INCEPTION_API_KEY"), # defaults to this env var; can be omitted
)
fim_completion = client.fim.completions.create(
model="mercury-edit-2",
prompt="def fibonacci(n: int) -> int:\n if n <= 1:\n return n\n return ",
suffix="\n\nprint(fibonacci(10))\n",
max_tokens=256,
)
print(fim_completion)import Inception from 'inceptionai';
const client = new Inception({
apiKey: process.env['INCEPTION_API_KEY'], // defaults to this env var; can be omitted
});
const fimCompletion = await client.fim.completions.create({
model: 'mercury-edit-2',
prompt: 'def fibonacci(n: int) -> int:\n if n <= 1:\n return n\n return ',
suffix: '\n\nprint(fibonacci(10))\n',
max_tokens: 256
});
console.log(fimCompletion);curl --request POST \
--url https://api.inceptionlabs.ai/v1/fim/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "mercury-edit-2",
"prompt": "def fibonacci(n: int) -> int:\n if n <= 1:\n return n\n return "
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'mercury-edit-2',
prompt: 'def fibonacci(n: int) -> int:\n if n <= 1:\n return n\n return '
})
};
fetch('https://api.inceptionlabs.ai/v1/fim/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/fim/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',
'prompt' => 'def fibonacci(n: int) -> int:
if n <= 1:
return n
return '
]),
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/fim/completions"
payload := strings.NewReader("{\n \"model\": \"mercury-edit-2\",\n \"prompt\": \"def fibonacci(n: int) -> int:\\n if n <= 1:\\n return n\\n return \"\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/fim/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"mercury-edit-2\",\n \"prompt\": \"def fibonacci(n: int) -> int:\\n if n <= 1:\\n return n\\n return \"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.inceptionlabs.ai/v1/fim/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 \"prompt\": \"def fibonacci(n: int) -> int:\\n if n <= 1:\\n return n\\n return \"\n}"
response = http.request(request)
puts response.read_body{
"id": "cmpl-7a2b3c4d5e",
"object": "text_completion",
"created": 1745798400,
"model": "mercury-edit-2",
"choices": [
{
"index": 0,
"finish_reason": "stop",
"text": "fibonacci(n - 1) + fibonacci(n - 2)"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 14,
"total_tokens": 38,
"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"
}
}FIM
Create a fill-in-the-middle completion
Generate a code completion given a prompt (prefix) and optional suffix. Designed for IDE-style inline completion. Returns a FimCompletion object, or a server-sent events stream of FimCompletionChunk deltas when stream=true. Tool calling and function calling are not supported.
POST
/
v1
/
fim
/
completions
Python
import os
from inceptionai import Inception
client = Inception(
api_key=os.environ.get("INCEPTION_API_KEY"), # defaults to this env var; can be omitted
)
fim_completion = client.fim.completions.create(
model="mercury-edit-2",
prompt="def fibonacci(n: int) -> int:\n if n <= 1:\n return n\n return ",
suffix="\n\nprint(fibonacci(10))\n",
max_tokens=256,
)
print(fim_completion)import Inception from 'inceptionai';
const client = new Inception({
apiKey: process.env['INCEPTION_API_KEY'], // defaults to this env var; can be omitted
});
const fimCompletion = await client.fim.completions.create({
model: 'mercury-edit-2',
prompt: 'def fibonacci(n: int) -> int:\n if n <= 1:\n return n\n return ',
suffix: '\n\nprint(fibonacci(10))\n',
max_tokens: 256
});
console.log(fimCompletion);curl --request POST \
--url https://api.inceptionlabs.ai/v1/fim/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "mercury-edit-2",
"prompt": "def fibonacci(n: int) -> int:\n if n <= 1:\n return n\n return "
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'mercury-edit-2',
prompt: 'def fibonacci(n: int) -> int:\n if n <= 1:\n return n\n return '
})
};
fetch('https://api.inceptionlabs.ai/v1/fim/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/fim/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',
'prompt' => 'def fibonacci(n: int) -> int:
if n <= 1:
return n
return '
]),
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/fim/completions"
payload := strings.NewReader("{\n \"model\": \"mercury-edit-2\",\n \"prompt\": \"def fibonacci(n: int) -> int:\\n if n <= 1:\\n return n\\n return \"\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/fim/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"mercury-edit-2\",\n \"prompt\": \"def fibonacci(n: int) -> int:\\n if n <= 1:\\n return n\\n return \"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.inceptionlabs.ai/v1/fim/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 \"prompt\": \"def fibonacci(n: int) -> int:\\n if n <= 1:\\n return n\\n return \"\n}"
response = http.request(request)
puts response.read_body{
"id": "cmpl-7a2b3c4d5e",
"object": "text_completion",
"created": 1745798400,
"model": "mercury-edit-2",
"choices": [
{
"index": 0,
"finish_reason": "stop",
"text": "fibonacci(n - 1) + fibonacci(n - 2)"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 14,
"total_tokens": 38,
"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
application/json
Response
Successful response. Returns a JSON object when stream=false, or a server-sent events stream of TextCompletionChunk objects (terminated by data: [DONE]) when stream=true.
Was this page helpful?