       if item.docid?
         add_model_static(elem, item.modelid, docs[item.docid])
       else if item.sessionid?
-        promise = add_model_from_session(elem, item.modelid, item.sessionid)
+        promise = add_model_from_session(elem, websocket_url, item.modelid, item.sessionid)
       else
         throw new Error("Error rendering Bokeh model #{item['modelid']} to element #{element_id}: no document ID or session ID specified")
     else
       if item.docid?
          add_document_static(elem, docs[item.docid], use_for_title)
       else if item.sessionid?
-         promise = add_document_from_session(elem, item.sessionid, use_for_title)
+         promise = add_document_from_session(elem, websocket_url, item.sessionid, use_for_title)
       else
         throw new Error("Error rendering Bokeh document to element #{element_id}: no document ID or session ID specified")
 

  logger.info("Will inject Bokeh script tag with params #{JSON.stringify(item)}")

embed_items = (docs_json, render_items, websocket_url) ->
  if websocket_url?
    set_websocket_url(websocket_url)

  docs = {}
  for docid of docs_json
    docs[docid] = Document.from_json(docs_json[docid])

add_document_static = (element, doc, use_for_title) ->
  _.delay(-> _render_document_to_element($(element), doc, use_for_title))

# map { websocket url to map { session id to promise of ClientSession } }
_sessions = {}
_get_session = (websocket_url, session_id) ->
  if not websocket_url? or websocket_url == null
    throw new Error("Missing websocket_url")
  if websocket_url not of _sessions
    _sessions[websocket_url] = {}
  subsessions = _sessions[websocket_url]
  if session_id not of subsessions
    subsessions[session_id] = pull_session(websocket_url, session_id)

  subsessions[session_id]

# Fill element with the roots from session_id
add_document_from_session = (element, websocket_url, session_id, use_for_title) ->
  promise = _get_session(websocket_url, session_id)
  promise.then(
    (session) ->
      _render_document_to_element(element, session.document, use_for_title)
