Code Completion

Complete a code prefix or fill code between a prefix and suffix
View as Markdown

Generates code at a cursor position.

POST /domains/models/capabilities/code-complete/execute

prompt is the code before the cursor. Optional suffix is the code that already exists after the cursor. The returned completionText belongs between them.

prompt + completionText + suffix

Request

import { AgentRouterClient } from "@agentrouter/agentrouter";
const client = new AgentRouterClient({
apiKey: process.env.AGENTIC_API_KEY,
});
const result = await client.models.code.complete.execute(
{
model: "deepseek-flash",
prompt: "const label = ",
suffix: "\nconsole.log(label);",
max_tokens: 80,
temperature: 0,
},
{
routeKey: "models.code.complete.deepseek.mpp",
allowFallback: false,
},
);
console.log(result.completionText);
console.log(result.creditsCharged);

Capability input

FieldTypeRequiredDescription
modelstringyesModel accepted by the selected code route. The current DeepSeek route accepts deepseek-flash, deepseek-v4-pro, and the deepseek-chat alias.
promptstringyesCode before the cursor.
suffixstringnoExisting code after the cursor. The model fills the gap.
max_tokensintegernoMaximum generated tokens. Must be at least 1; the DeepSeek wrapper default is 256.
temperaturenumbernoSampling temperature from 0 to 2. Use 0 for deterministic completion when possible.

Routing controls

FieldTypeRequiredDescription
routeKeystringnoPin models.code.complete.deepseek.mpp.
providerstringnoProvider hint. This route uses deepseek.
allowFallbackbooleannoAllow another compatible code route when available.

Code Completion model IDs are route-specific. A model ID from the OpenRouter chat catalog is not automatically valid for this endpoint.

Response

{
"success": true,
"completionText": "\"agentRouterSmoke\";",
"model": "deepseek-flash",
"provider": "deepseek",
"routeKey": "models.code.complete.deepseek.mpp",
"fallbackUsed": false,
"finishReason": "stop",
"usage": {
"promptTokens": 12,
"completionTokens": 4,
"totalTokens": 16
},
"creditsCharged": 3
}

The token counts and charge above are illustrative. Read them from the live response.

Response fields

FieldTypeDescription
completionTextstringCode inserted at the cursor.
modelstringCode model used.
providerstringProvider selected for execution.
routeKeystringConcrete route used.
fallbackUsedbooleanWhether execution used a fallback route.
finishReasonstringWhy generation stopped when available.
usageobjectProvider token usage when available.
creditsChargednumberAuthoritative final debit.

Reconstruct the file

const completedFile = prompt + result.completionText + suffix;

For a simple continuation, omit suffix:

const result = await client.models.code.complete.execute(
{
model: "deepseek-flash",
prompt: "export function slugify(value: string) {",
max_tokens: 120,
temperature: 0,
},
{ routeKey: "models.code.complete.deepseek.mpp" },
);

Inspect the exact route contract

const context = await client.catalog.routes.context(
"models.code.complete.deepseek.mpp",
);
console.log(context.execute?.fields);

Errors

StatusMeaningFix
400 or 422Missing model or prompt, or invalid parameterCompare the request with route context.
401Missing or invalid AgentRouter API keySend Authorization: Bearer aak_....
402Insufficient AgentRouter credits or payment-route fundingAdd funds, then retry.
404Code model or route is unavailableRefresh the route context and use a listed model ID.
429Provider or gateway rate limitRetry with exponential backoff.