Skip to main content
KiCad provides a gRPC-based API server that allows external applications to communicate with KiCad using Protocol Buffers. This enables programmatic control of KiCad from other languages and tools.

Overview

The KiCad API uses Protocol Buffers (protobuf) for message serialization and follows a request-response pattern. All API calls are wrapped in an envelope structure that provides status codes and error handling.

Connection

The API server runs on a local socket and uses protobuf messages for communication. Each request must be wrapped in an ApiRequest envelope and will receive an ApiResponse envelope.

Message Envelope

ApiRequest

All requests to KiCad must be wrapped in this envelope:
Fields:
  • header - Request metadata (see ApiRequestHeader)
  • message - The actual command message (type-encoded using protobuf Any)

ApiRequestHeader

Fields:
  • kicad_token - Opaque string to verify connection to same KiCad instance
  • client_name - Unique identifier for your client (e.g., “com.example.my_plugin-12345”)

ApiResponse

All responses from KiCad are wrapped in this envelope:
Fields:
  • header - Response metadata
  • status - Status code and error information
  • message - The response data (if successful)

ApiResponseStatus

Status Codes

Common Commands

Base Commands

GetVersion

Retrieves the KiCad version.

Ping

Checks if the connection is active.
Returns Empty message with AS_OK status.

GetTextExtents

Calculates the bounding box for text.
Returns kiapi.common.types.Box2 with text bounds.

GetPluginSettingsPath

Gets a writable path for plugin data storage.

Board Commands

All board commands are in the kiapi.board.commands package.

Board Stackup

GetBoardStackup

GetBoardEnabledLayers

SetBoardEnabledLayers

Warning: This operation deletes content on disabled layers and cannot be undone.

Board Origins

GetBoardOrigin

Returns Vector2 with the origin coordinates.

SetBoardOrigin

Net Management

GetNets

Retrieves all nets or filtered by netclass.

GetItemsByNet

Retrieves copper items belonging to specific nets.
Returns GetItemsResponse.

GetNetClassForNets

Retrieves the effective netclass for nets (merged from multiple classes).

Zone Operations

RefillZones

Blocking operation - KiCad returns AS_BUSY until complete.

Pad Utilities

GetPadShapeAsPolygon

Computes polygon representation of pad shapes.

CheckPadstackPresenceOnLayers

Tests if pads/vias have content on specific layers.

DRC Markers

InjectDrcError

Creates a DRC marker programmatically (available since v10.0).

PCB Editor Display

GetVisibleLayers / SetVisibleLayers

GetActiveLayer / SetActiveLayer

Board Appearance Settings

Interactive Commands

These commands begin interactive operations in the editor and return immediately, but KiCad becomes busy until the user completes the operation.

InteractiveMoveItems

Note: Takes ownership of the active commit. The move tool will push the commit when confirmed or roll back if cancelled.

Error Handling

Always check the status field in ApiResponse:

Best Practices

  1. Set client_name - Always provide a unique client identifier in the request header
  2. Handle AS_BUSY - Some operations are blocking; poll until KiCad is ready
  3. Check status codes - Always verify the response status before accessing message data
  4. Use kicad_token - For long-running clients, use tokens to ensure connection stability
  5. Batch operations - When possible, batch multiple item queries in a single request

Proto File Locations

The protocol buffer definitions are located in the KiCad source tree:
  • api/proto/common/ - Common types and base commands
  • api/proto/board/ - PCB board-specific commands
  • api/proto/schematic/ - Schematic-specific commands

See Also