0

Search and Execute Strale Capability

by
Published Apr 14, 2026

Search for a Strale capability using natural language and execute the best match. Combines capability discovery (/v1/suggest) with execution (/v1/do) in one step. Describe what data you need, provide the inputs, and Strale finds and runs the right capability. Includes a max_price_cents budget guard. Example: - task: "verify a Swedish company" - inputs: { "company_name": "Volvo AB" } - Result: structured company data from the Swedish business registry Strale provides 290+ quality-tested capabilities across company data, compliance, finance, web scraping, and more. Every result includes provenance and quality scores. Docs: https://strale.dev

Script strale Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 6 days ago
1
//native
2

3
// Search for a Strale capability and execute the best match.
4
// Combines /v1/suggest (semantic search) with /v1/do (execution) in one step.
5
// Useful in flows where you describe what data you need in natural language.
6
//
7
// Strale is the data layer for AI agents — every data source independently
8
// quality-tested, scored, and audit-logged. https://strale.dev
9

10
type Strale = {
11
  api_key: string;
12
  base_url?: string;
13
};
14

15
export async function main(
16
  strale: Strale,
17
  task: string,
18
  inputs: Record<string, unknown>,
19
  max_price_cents: number = 100,
20
  dry_run: boolean = false,
21
) {
22
  const baseUrl = strale.base_url ?? "https://api.strale.io";
23

24
  // Step 1: Search for matching capabilities
25
  const suggestResponse = await fetch(`${baseUrl}/v1/suggest`, {
26
    method: "POST",
27
    headers: {
28
      "Authorization": `Bearer ${strale.api_key}`,
29
      "Content-Type": "application/json",
30
    },
31
    body: JSON.stringify({ task, limit: 5 }),
32
  });
33

34
  if (!suggestResponse.ok) {
35
    const error = await suggestResponse.json().catch(() => ({ message: suggestResponse.statusText }));
36
    throw new Error(
37
      `Strale search error (${suggestResponse.status}): ${(error as any).error?.message ?? (error as any).message ?? "Unknown error"}`
38
    );
39
  }
40

41
  const suggestions = await suggestResponse.json() as {
42
    suggestions: Array<{
43
      slug: string;
44
      name: string;
45
      description: string;
46
      category: string;
47
      price_cents: number;
48
      quality_score?: number;
49
    }>;
50
  };
51

52
  if (!suggestions.suggestions?.length) {
53
    return {
54
      status: "no_match",
55
      task,
56
      message: "No matching capabilities found for this task.",
57
      suggestions: [],
58
    };
59
  }
60

61
  // Step 2: Pick best match within price budget
62
  const match = suggestions.suggestions.find((s) => s.price_cents <= max_price_cents);
63
  if (!match) {
64
    return {
65
      status: "over_budget",
66
      task,
67
      message: `Best match costs €${(suggestions.suggestions[0].price_cents / 100).toFixed(2)}, exceeds max €${(max_price_cents / 100).toFixed(2)}`,
68
      suggestions: suggestions.suggestions.map((s) => ({
69
        slug: s.slug,
70
        name: s.name,
71
        price: `€${(s.price_cents / 100).toFixed(2)}`,
72
      })),
73
    };
74
  }
75

76
  // Step 3: Execute the capability
77
  const doBody: Record<string, unknown> = {
78
    capability_slug: match.slug,
79
    inputs,
80
  };
81
  if (dry_run) {
82
    doBody.dry_run = true;
83
  }
84

85
  const doResponse = await fetch(`${baseUrl}/v1/do`, {
86
    method: "POST",
87
    headers: {
88
      "Authorization": `Bearer ${strale.api_key}`,
89
      "Content-Type": "application/json",
90
    },
91
    body: JSON.stringify(doBody),
92
  });
93

94
  if (!doResponse.ok) {
95
    const error = await doResponse.json().catch(() => ({ message: doResponse.statusText }));
96
    throw new Error(
97
      `Strale execution error (${doResponse.status}): ${(error as any).error?.message ?? (error as any).message ?? "Unknown error"}`
98
    );
99
  }
100

101
  const result = await doResponse.json() as {
102
    transaction_id?: string;
103
    capability_slug: string;
104
    status: string;
105
    output?: Record<string, unknown>;
106
    provenance?: Record<string, unknown>;
107
    quality?: Record<string, unknown>;
108
    cost_cents?: number;
109
    wallet_balance_cents?: number;
110
    dry_run?: boolean;
111
  };
112

113
  return {
114
    status: "success",
115
    task,
116
    matched_capability: {
117
      slug: match.slug,
118
      name: match.name,
119
      description: match.description,
120
      quality_score: match.quality_score,
121
    },
122
    transaction_id: result.transaction_id,
123
    output: result.output,
124
    provenance: result.provenance,
125
    quality: result.quality,
126
    cost: result.cost_cents != null ? `€${(result.cost_cents / 100).toFixed(2)}` : undefined,
127
    wallet_balance_cents: result.wallet_balance_cents,
128
    dry_run: result.dry_run,
129
    other_matches: suggestions.suggestions
130
      .filter((s) => s.slug !== match.slug)
131
      .slice(0, 3)
132
      .map((s) => ({ slug: s.slug, name: s.name, price: `€${(s.price_cents / 100).toFixed(2)}` })),
133
  };
134
}
Other submissions
  • Submitted by petter133 Deno
    Created 56 days ago
    1
    // Search for a Strale capability and execute the best match.
    2
    // Combines /v1/suggest (semantic search) with /v1/do (execution) in one step.
    3
    // Useful in flows where you describe what data you need in natural language.
    4
    //
    5
    // Strale is the data layer for AI agents — every data source independently
    6
    // quality-tested, scored, and audit-logged. https://strale.dev
    7
    
    
    8
    type Strale = {
    9
      api_key: string;
    10
      base_url?: string;
    11
    };
    12
    
    
    13
    export async function main(
    14
      strale: Strale,
    15
      task: string,
    16
      inputs: Record<string, unknown>,
    17
      max_price_cents: number = 100,
    18
      dry_run: boolean = false,
    19
    ) {
    20
      const baseUrl = strale.base_url ?? "https://api.strale.io";
    21
    
    
    22
      // Step 1: Search for matching capabilities
    23
      const suggestResponse = await fetch(`${baseUrl}/v1/suggest`, {
    24
        method: "POST",
    25
        headers: {
    26
          "Authorization": `Bearer ${strale.api_key}`,
    27
          "Content-Type": "application/json",
    28
        },
    29
        body: JSON.stringify({ task, limit: 5 }),
    30
      });
    31
    
    
    32
      if (!suggestResponse.ok) {
    33
        const error = await suggestResponse.json().catch(() => ({ message: suggestResponse.statusText }));
    34
        throw new Error(
    35
          `Strale search error (${suggestResponse.status}): ${(error as any).error?.message ?? (error as any).message ?? "Unknown error"}`
    36
        );
    37
      }
    38
    
    
    39
      const suggestions = await suggestResponse.json() as {
    40
        suggestions: Array<{
    41
          slug: string;
    42
          name: string;
    43
          description: string;
    44
          category: string;
    45
          price_cents: number;
    46
          quality_score?: number;
    47
        }>;
    48
      };
    49
    
    
    50
      if (!suggestions.suggestions?.length) {
    51
        return {
    52
          status: "no_match",
    53
          task,
    54
          message: "No matching capabilities found for this task.",
    55
          suggestions: [],
    56
        };
    57
      }
    58
    
    
    59
      // Step 2: Pick best match within price budget
    60
      const match = suggestions.suggestions.find((s) => s.price_cents <= max_price_cents);
    61
      if (!match) {
    62
        return {
    63
          status: "over_budget",
    64
          task,
    65
          message: `Best match costs €${(suggestions.suggestions[0].price_cents / 100).toFixed(2)}, exceeds max €${(max_price_cents / 100).toFixed(2)}`,
    66
          suggestions: suggestions.suggestions.map((s) => ({
    67
            slug: s.slug,
    68
            name: s.name,
    69
            price: `€${(s.price_cents / 100).toFixed(2)}`,
    70
          })),
    71
        };
    72
      }
    73
    
    
    74
      // Step 3: Execute the capability
    75
      const doBody: Record<string, unknown> = {
    76
        capability_slug: match.slug,
    77
        inputs,
    78
      };
    79
      if (dry_run) {
    80
        doBody.dry_run = true;
    81
      }
    82
    
    
    83
      const doResponse = await fetch(`${baseUrl}/v1/do`, {
    84
        method: "POST",
    85
        headers: {
    86
          "Authorization": `Bearer ${strale.api_key}`,
    87
          "Content-Type": "application/json",
    88
        },
    89
        body: JSON.stringify(doBody),
    90
      });
    91
    
    
    92
      if (!doResponse.ok) {
    93
        const error = await doResponse.json().catch(() => ({ message: doResponse.statusText }));
    94
        throw new Error(
    95
          `Strale execution error (${doResponse.status}): ${(error as any).error?.message ?? (error as any).message ?? "Unknown error"}`
    96
        );
    97
      }
    98
    
    
    99
      const result = await doResponse.json() as {
    100
        transaction_id?: string;
    101
        capability_slug: string;
    102
        status: string;
    103
        output?: Record<string, unknown>;
    104
        provenance?: Record<string, unknown>;
    105
        quality?: Record<string, unknown>;
    106
        cost_cents?: number;
    107
        wallet_balance_cents?: number;
    108
        dry_run?: boolean;
    109
      };
    110
    
    
    111
      return {
    112
        status: "success",
    113
        task,
    114
        matched_capability: {
    115
          slug: match.slug,
    116
          name: match.name,
    117
          description: match.description,
    118
          quality_score: match.quality_score,
    119
        },
    120
        transaction_id: result.transaction_id,
    121
        output: result.output,
    122
        provenance: result.provenance,
    123
        quality: result.quality,
    124
        cost: result.cost_cents != null ? `€${(result.cost_cents / 100).toFixed(2)}` : undefined,
    125
        wallet_balance_cents: result.wallet_balance_cents,
    126
        dry_run: result.dry_run,
    127
        other_matches: suggestions.suggestions
    128
          .filter((s) => s.slug !== match.slug)
    129
          .slice(0, 3)
    130
          .map((s) => ({ slug: s.slug, name: s.name, price: `€${(s.price_cents / 100).toFixed(2)}` })),
    131
      };
    132
    }