Could not find a valid session key
Same accepted answer: https://stackoverflow.com/a/51280077/4329215

If you build a custom form, Civi need some fields for when a new Drupal user is created.

1: Go to Civi profiles (/civicrm/admin/uf/group?reset=1) and select the desired profile you want to include in the form. I selected "Your registration form".
Go to settings of the profile and select "used for => Drupal User Registration"
In Advanced Settings check Account creation required

2: In your custom form, implement the function: 'civicrm_form_user_register_form_alter'. 

public function buildForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
    $validators = array(
        'file_validate_extensions' =&gt; array('jpg jpeg png'),
    );
    $form['uname'] = array(
        '#type' =&gt; 'textfield',
        '#placeholder' =&gt; t('Username*'),
        '#required' =&gt; TRUE,
        '#attributes' =&gt; array('class' =&gt; array('form-control')),
    );
    $form['organisation'] = array(
        '#type' =&gt; 'textfield',
        '#placeholder' =&gt; t('Organisation name*'),
        '#required' =&gt; TRUE,
        '#attributes' =&gt; array('class' =&gt; array('form-control')),
    );
    $form['password'] = array(
        '#type' =&gt; 'password_confirm',
        '#placeholder' =&gt; t('Password*'),
        '#required' =&gt; TRUE,
        '#attributes' =&gt; array('class' =&gt; array('form-control')),
    );
    $form['name'] = array(
        '#type' =&gt; 'textfield',
        '#placeholder' =&gt; t('Full Name*'),
        '#required' =&gt; TRUE,
        '#attributes' =&gt; array('class' =&gt; array('form-control')),
    );
    $form['email'] = array(
        '#type' =&gt; 'email',
        '#placeholder' =&gt; t('Email Address*'),
        '#required' =&gt; TRUE,
        '#attributes' =&gt; array('class' =&gt; array('form-control')),
    );

    $form['street'] = array(
        '#type' =&gt; 'textfield',
        '#placeholder' =&gt; t('Street*'),
        '#required' =&gt; TRUE,
        '#attributes' =&gt; array('class' =&gt; array('form-control')),
    );
    $form['nr'] = array(
        '#type' =&gt; 'textfield',
        '#placeholder' =&gt; t('Nr*'),
        '#required' =&gt; TRUE,
        '#attributes' =&gt; array('class' =&gt; array('form-control')),
    );
    $form['zipcode'] = array(
        '#type' =&gt; 'textfield',
        '#placeholder' =&gt; t('Zipcode*'),
        '#required' =&gt; TRUE,
        '#attributes' =&gt; array('class' =&gt; array('form-control')),
    );
    $form['city'] = array(
        '#type' =&gt; 'textfield',
        '#placeholder' =&gt; t('City*'),
        '#required' =&gt; TRUE,
        '#attributes' =&gt; array('class' =&gt; array('form-control')),
    );

    //This did the trick!
    if( function_exists('civicrm_form_user_register_form_alter') ) {
        civicrm_form_user_register_form_alter($form,$form_state,'customRegistration');
    }

    $form['actions'] = array('#type' =&gt; 'actions');
    $form['actions']['submit'] = array(
        '#type' =&gt; 'submit',
        '#value' =&gt; $this-&gt;t('Create'),
        '#attributes' =&gt; array('class' =&gt; array('btn', 'btn-cs', 'btn-outline')),
    );
    $form['#validate'][] = array($this, 'regValidate');
    return $form;
} 


2: In your template, add the fields with the field name from the Civi function:                 

{{custom_registration_form.civicrm_profile_register}}


You find the name in /modules/civicrm-drupal/civicrm.module 

$form['civicrm_profile_register'] = array(
    '#markup' =&gt; \Drupal\Core\Render\Markup::create($html),
    '#cache' =&gt; [
      'max-age' =&gt; 0,
    ],
);


The fields from the profile will be included in your custom form and no problems with sessions key anymore.