Modern communication and sensing technologies connect the optical domain with the microwave domain. Accessing the terahertz region from 100 GHz to 10 THz is critical for providing larger bandwidths capabilities. Despite progress in integrated electronics, they lack a direct link to the optical domain, and face challenges with increasing frequencies (> 1 THz). Electro-optic effects offer promising capabilities but are currently limited to bulk nonlinear crystals, missing out miniaturization, or to sub-terahertz bandwidths. Here, we address these challenges by realizing photonic circuits that integrate terahertz transmission lines on thin-film lithium niobate (TFLN). By providing terahertz field confinement and phase-matched interaction with optical fields, our miniaturized devices support low-noise and broad bandwidth terahertz generation and detection spanning four octaves (200 GHz to > 3 THz). By leveraging photonics’ advantages in low-loss and high-speed control, our platform achieves control over the terahertz spectrum and its amplitude, paving the way for compact and power-efficient devices with applications in telecommunications, spectroscopy, quantum electrodynamics and computing.