CookbookAll recipes

Cookbook

Short recipes that solve one problem each. Every recipe is complete: copy it, set SYNTIC_API_KEY, and run it against https://app.syntic.ai/v1. For explanations of the concepts behind them, follow the links at the end of each recipe.

Streaming

RecipeWhat it shows
Stream with curlWatch events arrive and pull out just the text with jq.
Stream in PythonPrint text as it arrives, with and without a client library.
Stream in Node.jsRead the event stream with fetch, and with the OpenAI client library.
Cancel a streamStop a reply partway, for a Stop button or a timeout.

Reliability and billing

RecipeWhat it shows
Retries with back-offRetry 429 and 5xx responses safely, honouring Retry-After.
Handle 402 quota_exhaustedTell the user why the request stopped and when it will work again.
Count cost from usageTurn each response’s usage into dollars and log it.

Tools

RecipeWhat it shows
Tool loop in PythonThe smallest complete tool loop, about 50 lines.
Tool loop in TypeScriptThe same loop with types.

Integration

RecipeWhat it shows
Call the API from a browserCORS, origin-restricted keys, and when to use a backend instead.
Move from the OpenAI SDKChange the base URL, key and model names; know what behaves differently.
Was this page helpful?