#404 for realtime/v1 API

1 messages · Page 1 of 1 (latest)

craggy plinth
#

I'm trying to follow the React hooks documentation, but I keep getting a 404. I've verifed that the accessToken is correct. I'm not really sure what else to try at this point.

Run Details

export function Run() {
    const { accessToken } = useTriggerAuthContext()
    const { run, error } = useRealtimeRun(
        'upload-and-generate-predictions-flow' satisfies UploadAndGeneratePredictionsFlowId,
        { accessToken },
    )

        console.log(JSON.stringify({ accessToken, error }))

    if (error) return <div>Error: {JSON.stringify(error)}</div>

    return <div>Run: {JSON.stringify(run)}</div>
}

Error:

{
  "accessToken": "ACCESS_TOKEN_HERE",
  "error": {
    "url": "https://api.trigger.dev/realtime/v1/runs/upload-and-generate-predictions-flow?offset=-1",
    "name": "FetchError",
    "status": 404,
    "json": {
      "error": "Not found"
    },
    "headers": {
      "content-type": "application/json; charset=utf-8"
    }
  }
}

Example of my decoded token:

{
  "sub": "SUB",
  "pub": true,
  "scopes": [
    "read:runs",
    "read:tags:app_instance_id",
    "read:tags:workspace_id",
    "read:tags:user_id"
  ],
  "iss": "https://id.trigger.dev",
  "aud": "https://api.trigger.dev",
  "iat": 1746068887,
  "exp": 1746069787
}
Trigger.dev

Find all the resources and guides you need to get started

sacred heartBOT
#

Hi @craggy plinth. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

craggy plinth
#

Trigger Provider

import { env } from '@core/env'
import { trpc } from '@core/trpc/server'
import { auth, configure } from '@trigger.dev/sdk/v3'
import type { PropsWithChildren } from 'react'
import { ClientProvider } from './client-provider'

// I tried adding this secret key, but it doesn't seem to make a difference.
configure({
    secretKey: env.TRIGGER_SECRET_KEY,
})

export async function TriggerServerProvider({ children }: PropsWithChildren) {
    const claims = await trpc.sessions.getClaims()
    const accessToken = await auth.createPublicToken({
        scopes: {
            read: {
                runs: true, // ❌ this token can read all runs, possibly useful for debugging/testing
                tags: [claims.appInstanceId, claims.workspaceId, claims.userId],
            },
        },
    })

    return <ClientProvider accessToken={accessToken}>{children}</ClientProvider>
}
sacred heartBOT
#

I can see you're having an issue with the Realtime API returning a 404 error when using the useRealtimeRun hook. Based on the error message and the knowledge sources, there are a few things to check:

Possible Issues

  1. Run ID Format: In your code, you're using 'upload-and-generate-predictions-flow' as the run ID, but this appears to be a task ID rather than a run ID. Run IDs typically have a format like run_1234.

  2. Known Issue with Large Payloads: There's a known issue with the Realtime API when subscribing to runs with large payloads:

    Realtime overview mentions: "There is currently a known issue where the realtime API does not work if subscribing to a run that has a large payload or large output and are stored in object store instead of the database... As a workaround you'll need to keep payloads and outputs below 128KB when using the realtime API."

Suggested Solutions

  1. Check Run ID Format: Make sure you're using an actual run ID (like run_1234) rather than a task ID. The useRealtimeRun hook expects a run ID, not a task ID.

  2. Use Task Trigger Hooks Instead: If you're trying to trigger a task and then subscribe to it, consider using one of these hooks instead:

  3. Verify API Endpoint: The error shows you're hitting <https://api.trigger.dev/realtime/v1/runs/...> - make sure this is the correct endpoint for your Trigger.dev instance, especially if you're self-hosting.

#
  1. Check Token Permissions: Your token has the correct read:runs scope, but it might need more specific permissions. Consider generating a new token with more specific scopes as shown in the Frontend Overview documentation.

If you're still experiencing issues, you might want to try using the SWR hooks like useRun instead of the Realtime hooks to see if that works better for your use case.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@craggy plinth Kapa.ai is still learning and improving, please let me know how I did by reacting below.