API and MCP documentation
One server, two doors: the MCP endpoint for AI assistants and a REST mirror of the same tools for scripts. The same sign-in, the same scopes, the same approval rules.
01Quick start
Quick start
Connect an AI assistant
Add the server address to your assistant and sign in to Valkiria. The steps for each assistant take about two minutes.
Setup steps for each assistantCall a tool over REST
Create an API key in the app and send the tool’s arguments as a JSON body. Every tool an assistant can call is also an HTTP endpoint.
Find the right tool
The tool reference lists every tool with its parameters, the scope it needs and a ready example.
Open the tool reference
curl -X POST https://valkiria.pro/api/v1/tools/get_started \
-H "Authorization: Bearer $VALKIRIA_TOKEN" \
-H "Content-Type: application/json" \
-d '{}'curl https://valkiria.pro/api/v1/tools \
-H "Authorization: Bearer $VALKIRIA_TOKEN"{
"count": 565,
"call": "POST /api/v1/tools/{name} with the arguments as a JSON body",
"tools": [
{
"name": "google_ads_campaigns",
"title": "…",
"description": "…",
"inputSchema": { "type": "object", "properties": { } },
"annotations": { "readOnlyHint": true, "destructiveHint": false, "idempotentHint": true, "openWorldHint": true }
}
]
}02Endpoints
Endpoints
POST
/mcpMCP server over Streamable HTTP. Every assistant connects to this address.
POST
/mcp/chatgptThe same server for ChatGPT, with the search and fetch tools its connectors require.
GET
/api/v1/toolsThe tools of your credential: name, title, description, input schema and annotations.
POST
/api/v1/tools/{name}Call one tool. The JSON body is the tool’s arguments.
GET
/api/v1/campaignsREST API v1: campaigns, analytics, rules and leads as resources. API keys only.
GET
/api/docs/openapi.jsonOpenAPI 3.0 description of REST API v1; a browsable page is at /api/docs.
GET
/.well-known/oauth-protected-resourceOAuth discovery documents (RFC 9728, RFC 8414) that MCP clients read by themselves.
All paths are relative to https://valkiria.pro
03Authentication
Authentication
Send the credential in the Authorization header as a Bearer token. Two kinds of credential work on both the MCP endpoint and the REST mirror.
OAuth 2.1 for connected assistants
Assistants sign in with OAuth 2.1: authorization code with PKCE (S256) and dynamic client registration. The access token lives one hour and the refresh token 30 days. OAuth connections work on every plan, including Free.
read— everything that only reads: campaigns, ad accounts, analytics, leads, rules, content, SEO and account health.propose— adds paused campaign and content drafts, AI generation, audits and change proposals. A proposal still waits for the owner’s approval.- A connected assistant cannot approve a change, resume or delete a campaign directly, or create, edit or delete automation rules. These stay with the owner in the app.
API keys for scripts and servers
Create a key in the app on the Developer API keys page. A key starts with vk_live_ and is shown in full only once; Valkiria keeps its hash. A key can have an expiry date and can be deleted at any time.
A key reaches only the tools its scopes allow. A new key gets campaigns:read, analytics:read and health:read unless you choose others. The tool reference shows the scope each tool asks for.
campaigns:readcampaigns:writeanalytics:readhealth:readleads:readleads:writerules:readrules:writecontent:readcontent:writesmm:readseo:readaso:readreports:readai:generate*
API keys need a plan with API access. On a plan without it a key is refused with HTTP 402 and works again after an upgrade; it is not deleted.
04Limits and metering
Limits and metering
Request rate
100 requests per minute per credential, shared by the MCP endpoint and the REST API. Above it the server answers 429; the RateLimit headers of every response tell how many requests are left and when the window resets.
HTTP/1.1 429
RateLimit-Policy: 100;w=60
RateLimit-Limit: 100
RateLimit-Remaining: 0
RateLimit-Reset: 42
Retry-After: 42
{ "error": "Too many API requests, please try again later" }Reading is free
Read-only tools are not counted against the plan. A fair-use limit of 2000 read calls a day applies; above it a read answers read_fair_use_limit with the reset time, midnight UTC.
Changes and AI generations
Tools that create a draft, propose a change or generate with AI spend the plan’s monthly allowance. Only successful calls are counted. When the allowance is used up the tool answers plan_limit_reached with the limit, the amount used and the reset date; reading keeps working. Rejecting a proposal is never counted.
Plans and allowances05Approval flow
Approval flow
A write tool does not change an ad account by itself. It creates a proposal; the account owner approves or rejects it; an applied change stays in the history, where it can be measured and undone.
- Propose. Call a proposal tool. The answer carries the proposal id, the state before and after, and the link to the approvals page. Nothing has changed in the ad account yet.
- Review. approvals_list returns everything that waits for a decision, approval_get returns one item, and approval_link returns the page where the owner decides.
- Decide. The owner approves in the app or in the Valkiria Telegram bot. An assistant can only reject, with approval_reject; the approval queue has no approve tool. A script with an API key can also approve a campaign-care recommendation with decide_campaign_recommendation; OAuth connections cannot.
- Check the effect. applied_changes_list shows what was applied; applied_change_impact compares the campaign’s real metrics for equal periods before and after the change.
- Undo. applied_change_request_undo queues the reverse change. It goes through the same approval.
Each ad account has a write policy set by its owner. By default a proposed change waits for approval; the owner can let some kinds of change apply by themselves or keep an account read-only. New campaigns are always created paused.
Worked example: add a negative keyword
The calls below were run on the demo account; the answers are shortened. In the demo account a change stays a proposal and is never sent to an ad platform.
curl -X POST https://valkiria.pro/api/v1/tools/google_ads_propose_add_negative_keywords \
-H "Authorization: Bearer $VALKIRIA_TOKEN" \
-H "Content-Type: application/json" \
-d '{"level":"campaign","id":"1342034425522269","terms":[{"text":"bikini schnittmuster","matchType":"EXACT"}],"reason":"98 EUR spent, no conversions in 30 days"}'{
"ok": true,
"tool": "google_ads_propose_add_negative_keywords",
"data": {
"proposal_id": "a1527d70-5875-4cc3-8032-c81fd6fa977f",
"status": "waiting_for_approval",
"approval_url": "https://valkiria.pro/approvals",
"entity": { "id": "1342034425522269", "name": "NF | Search — Brand + Category DE" },
"before": { "negativeKeywords": ["gratis", "jobs", "ausmalbilder", "second hand"] },
"after": { "negativeKeywords": ["gratis", "jobs", "ausmalbilder", "second hand", "bikini schnittmuster"] }
}
}curl -X POST https://valkiria.pro/api/v1/tools/approval_get \
-H "Authorization: Bearer $VALKIRIA_TOKEN" \
-H "Content-Type: application/json" \
-d '{"id":"a1527d70-5875-4cc3-8032-c81fd6fa977f"}'{
"ok": true,
"tool": "approval_get",
"data": {
"item": {
"id": "a1527d70-5875-4cc3-8032-c81fd6fa977f",
"platform": "google_ads",
"change_type": "negative_keyword",
"status": "queued",
"reason": "98 EUR spent, no conversions in 30 days",
"expected_impact": { "spend": "reduce" },
"applied_at": null
},
"approval_url": "https://valkiria.pro/approvals"
}
}curl -X POST https://valkiria.pro/api/v1/tools/approval_reject \
-H "Authorization: Bearer $VALKIRIA_TOKEN" \
-H "Content-Type: application/json" \
-d '{"id":"a1527d70-5875-4cc3-8032-c81fd6fa977f","reason":"Keep this search for now"}'{
"ok": true,
"tool": "approval_reject",
"data": { "id": "a1527d70-5875-4cc3-8032-c81fd6fa977f", "status": "rejected", "reason": "Keep this search for now" }
}# what was applied, newest first
curl -X POST https://valkiria.pro/api/v1/tools/applied_changes_list -H "Authorization: Bearer $VALKIRIA_TOKEN" -H "Content-Type: application/json" -d '{"limit":5}'
# metrics for equal periods before and after one change
curl -X POST https://valkiria.pro/api/v1/tools/applied_change_impact -H "Authorization: Bearer $VALKIRIA_TOKEN" -H "Content-Type: application/json" -d '{"operationId":"<id from applied_changes_list>"}'
# queue the reverse change (it waits for approval too)
curl -X POST https://valkiria.pro/api/v1/tools/applied_change_request_undo -H "Authorization: Bearer $VALKIRIA_TOKEN" -H "Content-Type: application/json" -d '{"operationId":"<id from applied_changes_list>"}'06Errors
Errors
The REST mirror answers with an HTTP status and a JSON body. A refusal by a tool comes back as HTTP 422 with ok set to false and the error in data. Over MCP the same refusal is a tool result with isError set and the same JSON as its text.
missing_bearer401No credential in the request. Send the Authorization: Bearer header.
invalid_token401The key or token is unknown, expired or revoked. Create a new key or sign in again.
plan_limit_reached402 / 422With HTTP 402: the plan gives API keys no access. As a tool error: the monthly allowance of changes and AI generations is used up; the answer carries limit, used and resets_at. Reading still works.
plan_unconfirmed503The plan could not be checked right now. Nothing ran; retry shortly.
invalid_tool_name, invalid_body400The tool name is malformed or the body is not a JSON object.
unknown_tool404This credential has no tool with that name. List the tools with GET /api/v1/tools.
MCP error -32602422The arguments do not match the tool’s input schema. The message names the argument.
insufficient_scope422The credential lacks the scope the tool asks for; required_scope names it. For OAuth connections it also marks actions reserved for the owner.
account_required422The tool needs an ad account id and no default account is set. Pass the id or save a default with set_default_account.
account_not_connected, account_not_found422The ad platform is not connected in this workspace, or the ad account id is not one of yours.
not_found422The object does not exist or belongs to another account.
client_restricted422The credential is limited to certain agency clients and cannot use this tool.
read_fair_use_limit422The daily fair-use limit of free reads is reached. The answer carries resets_at, midnight UTC.
temporarily_unavailable422Usage could not be verified right now. Nothing ran; retry shortly.
ai_unavailable422AI generation is temporarily unavailable. Retry later; the call was not counted.
invalid_request422The request was refused for the reason given in the message, for example a value outside the allowed range.
internal_error500 / 422Unexpected server error. Retry; if it repeats, contact support.
Too many API requests429More requests in a minute than allowed. Wait the number of seconds given in RateLimit-Reset.
HTTP/1.1 422
{
"ok": false,
"tool": "create_campaign",
"data": { "error": "insufficient_scope", "message": "Required scope: campaigns:write", "required_scope": "campaigns:write" }
}07Webhooks
Webhooks
The MCP server and the REST mirror do not send events. To follow a proposal, poll approvals_list and applied_changes_list; both are free reads. Outbound webhooks exist only in the Partner API and are set up together with the Valkiria team.
08Security and data handling
Security and data handling
- Access tokens of ad platforms stay on the server; no tool returns them.
- API keys and OAuth tokens are stored as SHA-256 hashes, never in plain form.
- Every tool call is written to the account’s connection log: tool name, result, error code and duration. Arguments are not stored there.
- A credential sees only its own workspace. An agency key can be limited to selected clients.
- An MCP session is bound to the credential that opened it; another credential gets 403.
- Disconnect an assistant on the Connect AI page or delete an API key at any time; the next request is refused.
09REST API v1
REST API v1
REST API v1 is the older resource-style API for campaigns, analytics, automation rules and leads. It accepts API keys only. New integrations get the same data, and much more, through the tool endpoints above.
Open the OpenAPI pagePOST /api/v1/campaigns — Create new campaign
// Local draft only: no advertising is published.
// Create one UUID per draft and save the complete request before sending.
// Retry this same saved UUID/body after a timeout; do not generate another.
const savedRequest = {
requestId: '54bda530-50ae-4bb4-bb8c-ae89fc26c029',
name: 'Ukraine product launch',
platform: 'telegram_ads',
objective: 'leads',
budget: 10000,
dailyBudget: 500,
currency: 'UAH',
targetAudience: {
countries: ['UA'],
languages: ['uk'],
interests: ['technology', 'business']
},
adContent: {
headline: 'Discover our product',
description: 'Explore the features for your business',
callToAction: 'Learn more'
}
};
// Run on your server. Keep the API key out of browser code.
const response = await fetch('https://valkiria.pro/api/v1/campaigns', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + process.env.VALKIRIA_API_KEY
},
body: JSON.stringify(savedRequest)
});
if (!response.ok) throw new Error('Creation not confirmed: HTTP ' + response.status);
const result = await response.json();
// Review the local draft; publication requires a separate approved workflow.
console.log(result.campaign.id, result.execution_scope);const response = await fetch('https://valkiria.pro/api/v1/tools/get_account_overview', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.VALKIRIA_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({}),
});
const { ok, data } = await response.json();
if (!ok) throw new Error(data?.error ?? `Valkiria API error: ${response.status}`);import os
import requests
response = requests.post(
"https://valkiria.pro/api/v1/tools/get_account_overview",
headers={"Authorization": f"Bearer {os.environ['VALKIRIA_TOKEN']}"},
json={},
timeout=60,
)
body = response.json()
if not body.get("ok"):
raise RuntimeError(body)
data = body["data"]10Changelog
Changelog
New tools and API changes are listed in the changelog. The tool reference is rebuilt from the server’s tool registry at every release, so it matches production; llms-tools.txt carries the same reference as plain text for language models.
Need help?
Didn't find an answer? Contact us