Developer documentation

TDLib JSON interface and multiple clients

Use the pinned TDLib header to understand td_send, td_receive, correlation, integer encoding and pointer lifetimes.

GetTGAPI editorial teamUpdated
Documentation notesReviewed

Source revision a94b83d67ab4 · TDLib contributors · BSL-1.0

Based on official sources and independently maintained by GetTGAPI. Documentation and glossary →

On this page
  1. Preserve the protocol’s JSON types
  2. Respect reception and pointer lifetimes
  3. Closure and the legacy interface
  4. Integration checks

Preserve the protocol’s JSON types

Objects use @type. A request can carry @extra, which the response preserves. The newer interface adds @client_id for routing across instances.

int64 values are strings; int32, int53 and double are numbers; bytes are Base64 strings. Do not coerce every identifier into a default floating-point type.

Respect reception and pointer lifetimes

Different threads may call td_send, but two threads must not call td_receive simultaneously. Apply updates and responses in reception order. The returned pointer remains valid only until the next td_receive or td_execute, so parse or copy it before handing work to asynchronous consumers.

Only methods explicitly documented as synchronous may use td_execute. Do not call TDLib methods from its log callback.

Closure and the legacy interface

New instances are destroyed automatically after closure, but all instances must be closed before application termination. Legacy td_json_client_* functions have a different lifecycle and a documented removal plan; do not mix cleanup conventions.

Integration checks

Assign unique request correlation values. A local wait timeout is not proof of business failure. Continue the receive loop even without outstanding application requests. Test simultaneous updates and closing one instance while another remains active.

Source license and attribution · BSL-1.0

TDLib contributors · Full license file

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.