> For the complete documentation index, see [llms.txt](https://painor.gitbook.io/gramjs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://painor.gitbook.io/gramjs/miscellaneous/initconnection.md).

# initConnection

Initialize connection

## Example

{% tabs %}
{% tab title="Javascript" %}

```javascript
const {Api, TelegramClient} = require('telegram');
const {StringSession} = require('telegram/sessions');

const session = new StringSession('');
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
    const result = await client.invoke(new Api.initConnection({
        apiId: 8925113,
        deviceModel: 'random string here',
        systemVersion: 'random string here',
        appVersion: 'random string here',
        systemLangCode: 'random string here',
        langPack: 'random string here',
        langCode: 'random string here',
        proxy: new Api.InputClientProxy({...}),
        params: new Api.JSONValue({...}),
        query: new Api.!X({...}),
        }));
    console.log(result); // prints the result
})();
```

{% endtab %}

{% tab title="TypeScript" %}

```typescript
import {Api, TelegramClient} from 'telegram';
import {StringSession} from 'telegram/sessions';

const session = new StringSession('');
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
    const result: Api.X = await client.invoke(new Api.initConnection({
        apiId: 8925113,
        deviceModel: 'random string here',
        systemVersion: 'random string here',
        appVersion: 'random string here',
        systemLangCode: 'random string here',
        langPack: 'random string here',
        langCode: 'random string here',
        proxy: new Api.InputClientProxy({...}),
        params: new Api.JSONValue({...}),
        query: new Api.!X({...}),
        }));
    console.log(result); // prints the result
})();
```

{% endtab %}
{% endtabs %}

## TL schema

```
---functions---
initConnection#c1cd5ea9 {X:Type} flags:# api_id:int device_model:string system_version:string app_version:string system_lang_code:string lang_pack:string lang_code:string proxy:flags.0?InputClientProxy params:flags.1?JSONValue query:!X = X;
```

## Parameters

|          Name          | Type                                                                                                                                               | Description                                                                                             |
| :--------------------: | -------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
|        **flags**       | [#](https://core.telegram.org/type/%23)                                                                                                            | Flags, see [TL conditional fields](https://core.telegram.org/mtproto/TL-combinators#conditional-fields) |
|       **api\_id**      | [int](https://core.telegram.org/type/int)                                                                                                          | Application identifier (see. [App configuration](https://core.telegram.org/myapp))                      |
|    **device\_model**   | [string](https://core.telegram.org/type/string)                                                                                                    | Device model                                                                                            |
|   **system\_version**  | [string](https://core.telegram.org/type/string)                                                                                                    | Operation system version                                                                                |
|    **app\_version**    | [string](https://core.telegram.org/type/string)                                                                                                    | Application version                                                                                     |
| **system\_lang\_code** | [string](https://core.telegram.org/type/string)                                                                                                    | Code for the language used on the device's OS, ISO 639-1 standard                                       |
|     **lang\_pack**     | [string](https://core.telegram.org/type/string)                                                                                                    | Language pack to use                                                                                    |
|     **lang\_code**     | [string](https://core.telegram.org/type/string)                                                                                                    | Code for the language used on the client, ISO 639-1 standard                                            |
|        **proxy**       | [flags](https://core.telegram.org/mtproto/TL-combinators#conditional-fields).0?[InputClientProxy](https://core.telegram.org/type/InputClientProxy) | Info about an MTProto proxy                                                                             |
|       **params**       | [flags](https://core.telegram.org/mtproto/TL-combinators#conditional-fields).1?[JSONValue](https://core.telegram.org/type/JSONValue)               | Additional initConnection parameters.                                                                   |

For now, only the tz\_offset field is supported, for specifying timezone offset in seconds.| |**query**|!X|The query itself|

## Result

X

## Possible errors

| Code | Type                       | Description   |
| :--: | -------------------------- | ------------- |
|  400 | CONNECTION\_LAYER\_INVALID | Layer invalid |

## Can bots use this methd ?

### yes

## Related pages
