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

# Use Providers With SDKs

> Connect Metorial provider tools to an LLM and build a chat-enabled app.

After you configure provider access in Metorial, you can connect those tools to an LLM like ChatGPT.

In this guide, you'll learn how to build a chat-enabled app that automatically handles tool calls from your Metorial providers.

<Note>
  **What you'll learn:**

  * How to use a Metorial provider
  * How to use the Metorial SDKs

  **Before you start:**

  * Create a Metorial project
  * Configure at least one provider or integration
  * Create an API key
</Note>

<Steps>
  <Step title="1. Install the SDKs">
    Run the installer for your language of choice:

    <CodeGroup>
      ```bash TypeScript theme={null}
      npm install metorial @metorial/openai openai
      ```

      ```bash Python theme={null}
      pip install metorial openai
      ```
    </CodeGroup>
  </Step>

  <Step title="2. Configure Clients">
    Instantiate both clients with your API keys and your provider deployment ID.

    <CodeGroup>
      ```typescript TypeScript theme={null}
      import { Metorial } from 'metorial';
      import { metorialOpenAI } from '@metorial/openai';
      import OpenAI from 'openai';

      let metorial = new Metorial({
        apiKey: '$$SECRET_TOKEN$$'
      });

      let openai = new OpenAI({
        apiKey: '...your-openai-api-key...'
      });
      ```

      ```python Python theme={null}
      from metorial import Metorial, metorial_openai
      from openai import AsyncOpenAI

      metorial = Metorial(api_key="$$SECRET_TOKEN$$")
      openai = AsyncOpenAI(api_key="...your-openai-api-key...")
      ```
    </CodeGroup>
  </Step>

  <Step title="3. Fetch Your Provider Tools">
    Create a session that exposes your deployed provider tools.

    <CodeGroup>
      ```typescript TypeScript theme={null}
      let session = await metorial.connect({
      	adapter: metorialOpenAI.chatCompletions(),
      	providers: [
      		{ providerDeploymentId: '...your-provider-deployment-id...' }
      	]
      });

      let tools = session.tools();
      ```

      ```python Python theme={null}
      session = await metorial.connect(
          adapter=metorial_openai(),
          providers=[{"provider_deployment_id": "...your-provider-deployment-id..."}],
      )
      tools = session.tools()
      ```
    </CodeGroup>
  </Step>

  <Step title="4. Send Your First Prompt">
    Kick off the loop by sending an initial message.

    <CodeGroup>
      ```typescript TypeScript theme={null}
      let messages = [
        { role: "user", content: "Summarize the README.md file of the metorial/websocket-explorer repository on GitHub." }
      ];
      ```

      ```python Python theme={null}
      messages = [
        {"role": "user", "content": "Summarize the README.md file of the metorial/websocket-explorer repository on GitHub."}
      ]
      ```
    </CodeGroup>
  </Step>

  <Step title="5. Loop & Handle Tool Calls">
    1. Send `messages` to OpenAI, passing the tools.
    2. If the assistant response contains `tool_calls`, invoke it:

    <CodeGroup>
      ```typescript TypeScript theme={null}
      let response = await openai.chat.completions.create({
        model: 'gpt-4o',
        messages,
        tools
      });
      let choice = response.choices[0]!;
      let toolCalls = choice.message.tool_calls;
      let toolResults = await session.callTools(toolCalls);
      ```

      ```python Python theme={null}
      response = await openai.chat.completions.create(
        model="gpt-4o",
        messages=messages,
        tools=session.tools(),
      )
      choice = response.choices[0]
      tool_calls = choice.message.tool_calls
      tool_results = await session.call_tools(tool_calls)
      ```
    </CodeGroup>

    3. Append both the tool call requests and their results to `messages`.
    4. Repeat until the assistant's response has no more `tool_calls`.
  </Step>

  <Step title="6. Display the Final Output">
    Once there are no more tool calls, your assistant's final reply is in:

    <CodeGroup>
      ```typescript TypeScript theme={null}
      console.log(choice.message.content);
      ```

      ```python Python theme={null}
      print(choice.message.content)
      ```
    </CodeGroup>
  </Step>
</Steps>

## What's Next?

You are set up to use Metorial provider tools in an application. Next, review the observability tooling available for sessions, connections, and tool calls.

<Card title="Next Up: How to monitor your provider and tool calls" icon="chart-line" href="/review-activity">
  Learn how to use the observability & logging features.
</Card>
