# get session id within a recipe

**URL:** <https://support.prodi.gy/t/get-session-id-within-a-recipe/2504>\
**Category:** Uncategorized\
**Tags:** enhancement, usage, streams\
**Created:** [February 5, 2020, 8:46am UTC](https://support.prodi.gy/t/get-session-id-within-a-recipe/2504 "2020-02-05T08:46:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnnaAnia](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/annaania/32/1073_2.png) [@AnnaAnia](https://support.prodi.gy/u/AnnaAnia)\
**Post date:** [February 5, 2020, 8:46am UTC](https://support.prodi.gy/t/get-session-id-within-a-recipe/2504/1 "2020-02-05T08:46:26Z")

</div>

Hi,

How do I retrieve the current session id (as in the URL) within a recipe to then use it in said recipe?

/?session=[user\_id]

I'm traying to access the session\_id via the controller but the import from your docs doesn't work

```python
from prodigy.controller import Controller

```

I'm using 1.8.5

Thanks

Anna

---

<div class="post-metadata">

**Author:** ![ines](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/ines/32/3_2.png) [@ines](https://support.prodi.gy/u/ines)\
**Post date:** [February 5, 2020, 10:43am UTC](https://support.prodi.gy/t/get-session-id-within-a-recipe/2504/2 "2020-02-05T10:43:15Z")

</div>

Hi! The session ID is only assigned when a user opens the app and makes a request to the server requesting a new batch of questions. There's not currently an in-recipe way to access it, because it's only available once the stream is already executing. So if you want fine-grained control like this within the recipe script, you'd currently have to use separate instances of Prodigy with different datasets, or the same dataset and sessions / annotator names / etc. set via the command line. This thread shows a flexible solution for this:

> [@Setting session name as a config or CLI option](https://support.prodi.gy/t/setting-session-name-as-a-config-or-cli-option/2490/2):
>
> Ah, so if I understand the use case correctly, you want to attach additional meta info to the data you're annotating that's preserved when you merge datasets? Recipes support a [get\_session\_id function](https://prodi.gy/docs/custom-recipes#components) that was initially added to override the default timestamp session IDs (e.g. if you're starting Prodigy instances programmatically and end up with multiple sessions per second). So in a custom recipe, you could add a [command-line argument](https://prodi.gy/docs/custom-recipes#recipe-args) for the annotator name and then "get\_session\_id": lambda: …

(I've been thinking about ways to make session-aware streams work without breaking backwards compatibility. Maybe we could introduce another callback that's executed when a session ID is assigned.)

> [@AnnaAnia](#):
>
> I'm traying to access the session\_id via the controller but the import from your docs doesn't work

Ah, this should be `from prodigy.core import Controller`. Will fix that. However, using it like this wouldn't work for your use case, since the `Controller` is the base class, and what you're looking for is the instance of the controller used for your current Prodigy session.

---

<div class="post-metadata">

**Author:** ![AnnaAnia](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/annaania/32/1073_2.png) [@AnnaAnia](https://support.prodi.gy/u/AnnaAnia)\
**Post date:** [February 5, 2020, 10:45am UTC](https://support.prodi.gy/t/get-session-id-within-a-recipe/2504/3 "2020-02-05T10:45:45Z")

</div>

> [@ines](#):
>
> o if you want fine-grained control like this within the recipe script, you'd currently have to use separate instances of Prodigy with different datasets, or the same dataset and sessions / annotator names / etc. set via the command line.

Do I need separate ports opened for it?

---

<div class="post-metadata">

**Author:** ![ines](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/ines/32/3_2.png) [@ines](https://support.prodi.gy/u/ines)\
**Post date:** [February 5, 2020, 10:49am UTC](https://support.prodi.gy/t/get-session-id-within-a-recipe/2504/4 "2020-02-05T10:49:28Z")

</div>

Yes, running different instances of different ports is the easiest way. (In theory, you could also use different hosts / different subdomains routed via a reverse proxy, but that's more work if you haven't set that up yet.)

---

<div class="post-metadata">

**Author:** ![AnnaAnia](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/annaania/32/1073_2.png) [@AnnaAnia](https://support.prodi.gy/u/AnnaAnia)\
**Post date:** [February 5, 2020, 10:51am UTC](https://support.prodi.gy/t/get-session-id-within-a-recipe/2504/5 "2020-02-05T10:51:45Z")

</div>

Thank you
