Circuit Simulator API

Posted on March 30, 2026 by Boden Bensema

Overview

URL: https://api.marsthelimit.com/simulate

Authentication: API Key required via header ("Authorization": "Bearer YOUR_API_KEY")

Supported format: JSON

The Circuit Simulator API lets you:

  • Simulate DC circuits (resistors, voltage sources, current sources, op-amps, BJTs)
  • Simulate AC circuits (resistors, capacitors, inductors, voltage sources)
  • Get node voltages and branch currents for any circuit topology
  • Model op-amp and BJT transistor behavior using standard small-signal models

All requests are made via a JSON payload.

Request Method

POST https://api.marsthelimit.com/simulate

Authentication: API Key required via header ("Authorization": "Bearer YOUR_API_KEY")

Body: JSON

Request Body

1{ 2 "nodes": ["gnd", "n1", "n2"], 3 "components": [...], 4 "analysis": { 5 "type": "dc" 6 } 7}

Fields

FieldTypeRequiredDescription
nodesarray of stringsYesList of node names. Must include "gnd" as the ground reference (0V).
componentsarray of objectsYesList of components in the circuit. See component types below.
analysisobjectNoAnalysis settings. Defaults to {"type": "dc"} if omitted.

Nodes

Nodes are the named connection points in your circuit, like the dots on a circuit diagram where wires meet. Every circuit must include "gnd" as the ground reference (always 0V). All other nodes can be named anything you like.

1"nodes": ["gnd", "n1", "n2", "n_out"]

Analysis Types

DC Analysis

Solves for steady-state voltages. Use for circuits powered by batteries or constant voltage/current sources.

1"analysis": {"type": "dc"}

AC Analysis

Solves for voltages at a specific frequency. Use for filters, amplifiers, and any circuit with capacitors or inductors. Returns magnitude and phase at each node.

1"analysis": {"type": "ac", "frequency": 1000}
FieldTypeRequiredDescription
typestringYes"ac"
frequencynumberYesFrequency in Hz

Component Types

Every component has a type field and an optional name field. The name field labels the component in the response. If omitted, the API automatically generates one (e.g. vsource_0).

Resistor

A resistor between two nodes.

1{ 2 "type": "resistor", 3 "name": "R1", 4 "n1": "n1", 5 "n2": "n2", 6 "value": 1000 7}
FieldTypeDescription
n1stringFirst node
n2stringSecond node
valuenumberResistance in ohms (Ω)

Voltage Source

A fixed voltage source such as a battery. This introduces a branch current variable in the solver.

1{ 2 "type": "vsource", 3 "name": "V_battery", 4 "n_plus": "n1", 5 "n_minus": "gnd", 6 "value": 10 7}
FieldTypeDescription
n_plusstringPositive terminal node
n_minusstringNegative terminal node
valuenumberVoltage in volts (V)

Current Source

A fixed current source. Current flows from n_minus to n_plus through the source.

1{ 2 "type": "isource", 3 "name": "I1", 4 "n_plus": "n1", 5 "n_minus": "gnd", 6 "value": 0.01 7}
FieldTypeDescription
n_plusstringNode current flows into
n_minusstringNode current flows out of
valuenumberCurrent in amps (A)

Capacitor

A capacitor between two nodes. Treated as an open circuit for DC analysis. For AC analysis, impedance = 1 / (jωC).

1{ 2 "type": "capacitor", 3 "name": "C1", 4 "n1": "n1", 5 "n2": "gnd", 6 "value": 0.000001 7}
FieldTypeDescription
n1stringFirst node
n2stringSecond node
valuenumberCapacitance in farads (F)

Inductor

An inductor between two nodes. Treated as a short circuit (wire) for DC analysis. For AC analysis, impedance = jωL.

1{ 2 "type": "inductor", 3 "name": "L1", 4 "n1": "n1", 5 "n2": "n2", 6 "value": 0.001 7}
FieldTypeDescription
n1stringFirst node
n2stringSecond node
valuenumberInductance in henries (H)

Op-Amp

An ideal op-amp. Enforces V(n_plus) = V(n_minus) and sources whatever current is needed at the output. Requires a feedback path in the circuit or the matrix will be singular.

1{ 2 "type": "opamp", 3 "name": "U1", 4 "n_plus": "gnd", 5 "n_minus": "n2", 6 "n_out": "n_out" 7}
FieldTypeDescription
n_plusstringNon-inverting input (+)
n_minusstringInverting input (−)
n_outstringOutput node

BJT Transistor (Small-Signal)

A BJT transistor using the small-signal model. This model is linearized around an operating point. It is best suited for AC small-signal analysis or DC analysis with a supply voltage present. Requires a collector supply voltage to produce physically meaningful results.

1{ 2 "type": "bjt", 3 "name": "Q1", 4 "n_b": "n_b", 5 "n_c": "n_c", 6 "n_e": "n_e", 7 "gm": 0.04, 8 "rpi": 2500, 9 "ro": 100000 10}
FieldTypeDescription
n_bstringBase node
n_cstringCollector node
n_estringEmitter node
gmnumberTransconductance in siemens (A/V). Typical: Ic / 0.026
rpinumberBase-emitter resistance in ohms. Typical: β / gm
ronumberOutput resistance in ohms. Typical: Va / Ic

Response

1{ 2 "success": true, 3 "node_voltages": { 4 "n1": {"real": 10.0}, 5 "n2": {"real": 5.0} 6 }, 7 "branch_currents": { 8 "V_battery": {"real": -0.005} 9 } 10}

Node Voltages

Each non-ground node appears in node_voltages.

DC response:

1"n1": {"real": 10.0}
FieldDescription
realVoltage in volts (V)

AC response:

1"n1": { 2 "magnitude": 0.707, 3 "phase_deg": -45.0, 4 "real": 0.5, 5 "imag": -0.5 6}
FieldDescription
magnitudePeak voltage amplitude in volts (V)
phase_degPhase angle in degrees relative to source
realReal part of the complex voltage
imagImaginary part of the complex voltage

Branch Currents

Branch currents are returned for voltage sources, op-amps, and inductors, or components that add a branch current unknown to the simulation. The key is the component's name field (or auto-generated label if none was provided).

DC response:

1"V_battery": {"real": -0.005}

A negative value means current flows out of the positive terminal into the circuit, which is the standard convention.

Errors

HTTP StatusErrorCause
400"No JSON body provided"Request body is missing or malformed
400"Missing field: nodes"Required field not present in body
422"Singular matrix - check your circuit for floating nodes"A node has no path to ground, or an op-amp has no feedback
500Internal error messageUnexpected error; check component values and node names

Common causes of singular matrix

  • A node is defined in nodes but no component connects it to anything
  • An op-amp has no feedback resistor (the output is not connected back to the inverting input)
  • A capacitor is the only path to ground for a node in DC analysis (capacitors are open circuits for DC)
  • A BJT emitter node has no resistor connecting it to ground

Examples

Voltage divider (DC)

Two equal resistors splitting a 10V supply. Expects n1 = 10V, n2 = 5V.

1{ 2 "nodes": ["gnd", "n1", "n2"], 3 "components": [ 4 {"type": "vsource", "name": "V1", "n_plus": "n1", "n_minus": "gnd", "value": 10}, 5 {"type": "resistor", "name": "R1", "n1": "n1", "n2": "n2", "value": 1000}, 6 {"type": "resistor", "name": "R2", "n1": "n2", "n2": "gnd", "value": 1000} 7 ], 8 "analysis": {"type": "dc"} 9}

RC low-pass filter (AC)

At the cutoff frequency f = 1/(2πRC) ≈ 159Hz, the output magnitude should be ≈ 0.707 (-3dB) with a phase of -45°.

1{ 2 "nodes": ["gnd", "n1", "n2"], 3 "components": [ 4 {"type": "vsource", "name": "V_in", "n_plus": "n1", "n_minus": "gnd", "value": 1}, 5 {"type": "resistor", "name": "R1", "n1": "n1", "n2": "n2", "value": 1000}, 6 {"type": "capacitor", "name": "C1", "n1": "n2", "n2": "gnd", "value": 0.000001} 7 ], 8 "analysis": {"type": "ac", "frequency": 159.15} 9}

Inverting op-amp amplifier (DC)

Gain = -R2/R1 = -1. With V_in = 2V, expects n_out = -2V and n2 ≈ 0V (virtual ground).

1{ 2 "nodes": ["gnd", "n1", "n2", "n_out"], 3 "components": [ 4 {"type": "vsource", "name": "V_in", "n_plus": "n1", "n_minus": "gnd", "value": 2}, 5 {"type": "resistor", "name": "R1", "n1": "n1", "n2": "n2", "value": 1000}, 6 {"type": "resistor", "name": "R2", "n1": "n2", "n2": "n_out", "value": 1000}, 7 {"type": "opamp", "name": "U1", "n_plus": "gnd", "n_minus": "n2", "n_out": "n_out"} 8 ], 9 "analysis": {"type": "dc"} 10}

BJT common-emitter amplifier (DC)

Gain ≈ -gm × Rc = -0.04 × 10000 = -400. With V_in = 0.01V, expects n_c ≈ 1V (pulled down 4V from Vcc=5V).

1{ 2 "nodes": ["gnd", "n_b", "n_c", "n_e", "vcc"], 3 "components": [ 4 {"type": "vsource", "name": "Vcc", "n_plus": "vcc", "n_minus": "gnd", "value": 5}, 5 {"type": "vsource", "name": "V_in", "n_plus": "n_b", "n_minus": "gnd", "value": 0.01}, 6 {"type": "resistor", "name": "Rc", "n1": "vcc", "n2": "n_c", "value": 10000}, 7 {"type": "resistor", "name": "Re", "n1": "n_e", "n2": "gnd", "value": 100}, 8 {"type": "bjt", "name": "Q1", "n_b": "n_b", "n_c": "n_c", "n_e": "n_e", 9 "gm": 0.04, "rpi": 2500, "ro": 100000} 10 ], 11 "analysis": {"type": "dc"} 12}

Notes

  • Ground ("gnd") is always 0V and is excluded from the response. It is the reference point for all other voltages.
  • Node names are case-sensitive. "N1" and "n1" are treated as different nodes.
  • The BJT model is a linear small-signal approximation. It does not model saturation, cutoff, or thermal effects.
  • The op-amp model is ideal: infinite gain, infinite input impedance, zero output impedance. It does not model slew rate, bandwidth limits, or supply rail clamping.
  • For AC analysis, capacitors should not be the only path to ground for any node. They are open circuits at DC and will cause a singular matrix if no DC path exists.

About the Author

This article was written by Boden Bensema, an electronics hobbyist focused on teaching beginner-friendly circuit design, breadboarding, and electronics fundamentals.

About page