# Supabase RPC

import { Aside, CardGrid, LinkCard } from '@astrojs/starlight/components';
import SecuritySetupWarning from '@/components/SecuritySetupWarning.astro';

Use Supabase RPC to start pgflow workflows with simple function calls when you don't need real-time progress updates.

<Aside type="tip">
This approach is best for **fire-and-forget workflows** where you don't need to monitor progress or wait for results.

For real-time progress streaming, status monitoring, or waiting for completion, use the [TypeScript Client](/build/starting-flows/typescript-client/) instead.
</Aside>

<SecuritySetupWarning />

## Basic Usage

Start a workflow by calling the `pgflow.start_flow` function via RPC:

```typescript
import { createClient } from '@supabase/supabase-js';

const supabase = createClient(
  'https://your-project.supabase.co',
  'your-anon-key'
);

// Start a workflow
const { data, error } = await supabase
  .schema('pgflow')
  .rpc('start_flow', {
    flow_slug: 'send_welcome_email',
    input: {
      email: 'user@example.com',
      name: 'John Doe'
    }
  });

if (error) {
  console.error('Failed to start workflow:', error);
} else {
  console.log('Workflow started with run_id:', data);
}
```

<Aside type="note" title="Calling Functions in Custom Schemas">
pgflow functions are in the `pgflow` schema, not the default `public` schema. To call RPC functions in custom schemas, use `.schema('schema_name').rpc('function_name')`. See the [Supabase team's guidance on GitHub](https://github.com/supabase/supabase-flutter/issues/639#issuecomment-1730487098) for details.
</Aside>

## With Custom Run ID

Provide a custom UUID for the workflow run:

```typescript
import { randomUUID } from 'crypto';

const run_id = randomUUID();

const { data, error } = await supabase
  .schema('pgflow')
  .rpc('start_flow', {
    flow_slug: 'process_upload',
    input: {
      file_url: 'https://example.com/file.pdf'
    },
    run_id: run_id
  });

console.log('Started workflow:', run_id);
```

<Aside type="tip">
For monitoring workflow progress, checking status, or waiting for completion, use the [TypeScript Client](/build/starting-flows/typescript-client/) instead. It provides real-time progress updates and robust status monitoring without polling.
</Aside>

## Learn More

<CardGrid>
  <LinkCard
    title="TypeScript Client"
    href="/build/starting-flows/typescript-client/"
    description="Use the full client library for real-time progress streaming"
  />
</CardGrid>