> ## Documentation Index
> Fetch the complete documentation index at: https://docs.promptjuggler.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a streaming credential for a thread

> Returns a short-lived, thread-scoped token your frontend can use to subscribe to live token output over SSE. Call this from your backend with your API key, then hand the token to the browser — the API key itself must never leave your server. The thread does not have to exist yet: mint a token, connect, then start the run. Connect before triggering a run, since tokens emitted while nobody is subscribed are not replayed.



## OpenAPI

````yaml /openapi.json post /api/v1/threads/{thread}/stream-token
openapi: 3.1.1
info:
  title: PromptJuggler
  description: PromptJuggler API
  version: 1.0.0
servers:
  - url: https://promptjuggler.com
security:
  - Bearer: []
tags:
  - name: Prompts
    description: Fetch prompts and revisions.
  - name: Prompt Runs
    description: Execute published prompts and retrieve results.
  - name: Workflow Runs
    description: Execute multi-step workflows and retrieve results.
  - name: Knowledge Bases
    description: Upload and manage documents used for retrieval-augmented generation.
  - name: Streaming
    description: Subscribe to live token output as runs produce it.
paths:
  /api/v1/threads/{thread}/stream-token:
    post:
      tags:
        - Streaming
      summary: Create a streaming credential for a thread
      description: >-
        Returns a short-lived, thread-scoped token your frontend can use to
        subscribe to live token output over SSE. Call this from your backend
        with your API key, then hand the token to the browser — the API key
        itself must never leave your server. The thread does not have to exist
        yet: mint a token, connect, then start the run. Connect before
        triggering a run, since tokens emitted while nobody is subscribed are
        not replayed.
      operationId: create_stream_token
      parameters:
        - name: thread
          in: path
          description: >-
            Thread ID to subscribe to. Any UUID you intend to run against — the
            token is scoped to your tenant, so threads cannot collide across
            tenants.
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '200':
          description: Streaming credential
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StreamTokenResponse'
        '401':
          description: Missing or invalid API key
        '403':
          description: No active subscription
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Malformed thread ID
      x-codeSamples:
        - lang: PHP
          label: PromptJuggler PHP SDK
          source: >-
            $token =
            $pj->createStreamToken('0198f0e2-9c3a-7c1d-8f4b-2a6d5e7c9b10');
        - lang: TypeScript
          label: PromptJuggler TypeScript SDK
          source: >-
            const token = await
            pj.createStreamToken('0198f0e2-9c3a-7c1d-8f4b-2a6d5e7c9b10');
        - lang: Python
          label: PromptJuggler Python SDK
          source: >-
            token =
            pj.create_stream_token('0198f0e2-9c3a-7c1d-8f4b-2a6d5e7c9b10')
        - lang: Java
          label: PromptJuggler Java SDK
          source: >-
            StreamTokenResponse token =
            pj.createStreamToken("0198f0e2-9c3a-7c1d-8f4b-2a6d5e7c9b10");
        - lang: Go
          label: PromptJuggler Go SDK
          source: >-
            token, err := pj.CreateStreamToken(ctx,
            "0198f0e2-9c3a-7c1d-8f4b-2a6d5e7c9b10")
components:
  schemas:
    StreamTokenResponse:
      description: A short-lived credential for subscribing to a thread's token stream.
      required:
        - token
        - expiresAt
        - url
      properties:
        token:
          description: >-
            Bearer token for the streaming endpoint. Safe to hand to a browser —
            it grants read access to this one thread and nothing else.
          type: string
        expiresAt:
          description: Timestamp when the token stops being accepted.
          type: string
          format: date-time
        url:
          description: >-
            Fully-resolved SSE endpoint for this thread. Connect here with the
            token as a Bearer credential.
          type: string
          example: >-
            https://stream.promptjuggler.com/stream/0198f0e2-9c3a-7c1d-8f4b-2a6d5e7c9b10
      type: object
    ErrorResponse:
      description: Error response.
      required:
        - error
      properties:
        error:
          description: Error message.
          type: string
      type: object
  securitySchemes:
    Bearer:
      type: http
      scheme: bearer

````