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

# LiteLLM

> Use the LiteLLM backend to reach Gemini, Together, DeepInfra, and many other providers.

Curator can send requests through [LiteLLM](https://docs.litellm.ai/docs/providers), which supports many LLM providers. Curator picks the LiteLLM backend on its own for most models that are not from OpenAI, Anthropic, or Mistral. You can also choose it with `backend="litellm"`.

This guide generates recipes with Gemini.

## Prerequisites

* Python 3.10 or later.
* Curator, installed with `pip install bespokelabs-curator`.
* An API key for your provider. For Gemini, get one from [Google AI Studio](https://aistudio.google.com/app/apikey).

<Steps>
  <Step title="Create an LLM subclass">
    ```python theme={null}
    from datasets import Dataset

    from bespokelabs import curator


    class RecipeGenerator(curator.LLM):
        """Generate recipes for different cuisines."""

        def prompt(self, input: dict) -> str:
            return f"Generate a random {input['cuisine']} recipe. Be creative but keep it realistic."

        def parse(self, input: dict, response: str) -> dict:
            return {"recipe": response, "cuisine": input["cuisine"]}
    ```
  </Step>

  <Step title="Create the input dataset">
    ```python theme={null}
    cuisines = Dataset.from_list([
        {"cuisine": cuisine}
        for cuisine in [
            "Chinese", "Italian", "Mexican", "French", "Japanese",
            "Indian", "Thai", "Korean", "Vietnamese", "Brazilian",
        ]
    ])
    ```
  </Step>

  <Step title="Set the API key">
    ```bash theme={null}
    export GEMINI_API_KEY=<your-api-key>
    ```
  </Step>

  <Step title="Configure the LiteLLM backend">
    Use the model name in LiteLLM format, which starts with the provider prefix.

    ```python theme={null}
    recipe_generator = RecipeGenerator(
        model_name="gemini/gemini-2.5-flash",
        backend="litellm",
        backend_params={
            "max_requests_per_minute": 2_000,
            "max_tokens_per_minute": 4_000_000,
        },
    )
    ```

    Set the rate limits to match your account. See [Online processing](/curator/guides/online-processing#rate-limit-settings) for all the rate limit settings.
  </Step>

  <Step title="Generate the data">
    ```python theme={null}
    recipes = recipe_generator(cuisines)
    print(recipes.dataset.to_pandas())
    ```
  </Step>
</Steps>

## Other providers

Each provider needs its own API key and model prefix. The [LiteLLM provider list](https://docs.litellm.ai/docs/providers) has the details for every provider.

<Tabs>
  <Tab title="Together">
    ```bash theme={null}
    export TOGETHER_API_KEY=<your-api-key>
    ```

    ```python theme={null}
    recipe_generator = RecipeGenerator(
        model_name="together_ai/meta-llama/Llama-3.3-70B-Instruct-Turbo",
        backend="litellm",
    )
    ```

    Find other models in the [Together model list](https://api.together.ai/models). Some models do not support structured output.
  </Tab>

  <Tab title="DeepInfra">
    ```bash theme={null}
    export DEEPINFRA_API_KEY=<your-api-key>
    ```

    ```python theme={null}
    recipe_generator = RecipeGenerator(
        model_name="deepinfra/meta-llama/Llama-3.3-70B-Instruct",
        backend="litellm",
    )
    ```

    Find other models in the [DeepInfra model list](https://deepinfra.com/models), and add the `deepinfra/` prefix to the name.
  </Tab>
</Tabs>
