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

# Monitoring Quickstart

> Monitor your LLM requests and application functions.

<Steps>
  <Step title="Installation">
    First, you'll need a Parea API key. See [Authentication](/api-reference/authentication) to get started.

    After you've followed those steps, you are ready to install the Parea SDK client.

    <CodeGroup>
      ```bash python theme={null}
      pip install parea-ai
      ```

      ```bash node theme={null}
      npm install parea-ai
      ```
    </CodeGroup>
  </Step>

  <Step title="Start Logging">
    Use any of the code snippets below to start logging your LLM requests.

    <Tabs>
      <Tab title="Python">
        Parea supports automatic logging for OpenAI, Anthropic, Langchain, or any model if using Parea's completion method.

        The `@trace` decorator allows you to associate multiple functions into a single trace.

        <CodeGroup>
          ```python openai.py theme={null}
          from openai import OpenAI
          from parea import Parea

          client = OpenAI(api_key="OPENAI_API_KEY")  # replace with your API key
          p = Parea(api_key="PAREA_API_KEY")  # replace with your API key
          p.wrap_openai_client(client)  # if OpenAI python version < 1.0.0: p.wrap_openai_client(openai)

          response = client.chat.completions.create(
              model="gpt-3.5-turbo",
              temperature=0.5,
              messages=[
                  {
                      "role": "user",
                      "content": "Write a Hello World program in Python using FastAPI.",
                  }
              ],
          )
          print(response.choices[0].message.content)
          ```

          ```python anthropic.py theme={null}
          import anthropic
          from parea import Parea

          p = Parea(api_key="PAREA_API_KEY")  # replace with your API key

          client = anthropic.Anthropic()
          p.wrap_anthropic_client(client)

          message = client.messages.create(
              model="claude-3-opus-20240229",
              max_tokens=1024,
              messages=[
                  {
                      "role": "user",
                      "content": "Write a Hello World program in Python using FastAPI.",
                  }
              ],
          )
          print(message.content[0].text)
          ```

          ```python parea_completion.py theme={null}
          from parea import Parea
          from parea.schemas import LLMInputs, Message, ModelParams, Role, Completion

          p = Parea(api_key="PAREA_API_KEY")  # replace with your API key

          response = p.completion(
              Completion(llm_configuration=LLMInputs(
                  model="gpt-3.5-turbo",  # this can be any model enabled on Parea
                  model_params=ModelParams(temp=0.5),
                  messages=[Message(
                      role=Role.user,
                      content="Write a Hello World program in Python using FastAPI.",
                  )],
              ))
          )
          print(response.content)
          ```

          ```python trace_decorator.py theme={null}
          from parea import Parea, trace
          from parea.schemas import LLMInputs, Message, ModelParams, Completion

          p = Parea(api_key="PAREA_API_KEY")

          def llm(messages: list[dict[str, str]]):
              return p.completion(
                  Completion(
                      llm_configuration=LLMInputs(
                          model="gpt-3.5-turbo",
                          model_params=ModelParams(temp=0.5),
                          messages=[Message(**m) for m in messages],
                      )
                  )
              ).content

          def hello_world(lang: str, framework: str):
              return llm([{"role": "user", "content": f"Write a Hello World program in {lang} using {framework}."}])

          def critique_code(code: str):
              return llm([{"role": "user", "content": f"How can we improve this code: \n {code}"}])

          @trace(metadata={"purpose": "example"}, end_user_identifier="John Doe")
          def chain(lang: str, framework: str) -> str:
              return critique_code(hello_world(lang, framework))

          print(chain("Python", "FastAPI"))
          ```

          ```python langchain.py theme={null}
          from langchain_core.output_parsers import StrOutputParser
          from langchain_core.prompts import ChatPromptTemplate
          from langchain_openai import ChatOpenAI
          from parea import Parea
          from parea.utils.trace_integrations.langchain import PareaAILangchainTracer

          p = Parea(api_key="PAREA_API_KEY")  # replace with your API key
          handler = PareaAILangchainTracer()

          llm = ChatOpenAI(openai_api_key="OPENAI_API_KEY")  # replace with your API key
          prompt = ChatPromptTemplate.from_messages([("user", "{input}")])
          chain = prompt | llm | StrOutputParser()

          response = chain.invoke(
              {"input": "Write a Hello World program in Python using FastAPI."},
              config={"callbacks": [handler]},
          )
          print(response)
          ```
        </CodeGroup>
      </Tab>

      <Tab title="Typescript">
        Parea supports automatic logging for OpenAI or any model using Parea's completion method.
        Support for Anthropic's Claude is coming soon (reach out for early access).

        The `trace()` wrapper allows you to associate multiple functions into a single trace.

        <CodeGroup>
          ```typescript openai.ts theme={null}
          import OpenAI from 'openai';
          import {Parea, patchOpenAI} from "parea-ai";

          new Parea("PAREA_API_KEY"); // still needed for tracing, replace with your API key
          const openai = new OpenAI();
          patchOpenAI(openai);

          async function main(): Promise<string | null> {
              const response = await openai.chat.completions.create({
                  messages: [{role: 'user', content: "Write a hello world program in Python using FastAPI."}],
                  model: 'gpt-3.5-turbo',
              })
              return response.choices[0].message.content;
          }
          ```

          ```typescript parea_completion.ts theme={null}
          import {Parea} from "parea-ai";

          const p = new Parea("PAREA_API_KEY"); // replace with your API key

          async function main(): Promise<string | null> {
              const response = await p.completion({
                  llm_configuration: {
                      model: 'gpt-3.5-turbo',
                      model_params: {temp: 0.5},
                      messages: [{role: 'user', content: "Write a hello world program in Python using FastAPI."}],
                  }
              });
              return response.content
          }
          ```

          ```typescript trace_wrapper.ts theme={null}
          import {CompletionResponse, Message, Parea, trace} from "parea-ai";

          const p = new Parea("PAREA_API_KEY") // replace with your API key

          async function llm(messages: Message[]): Promise<string | null> {
              const response: CompletionResponse = await p.completion({
                  llm_configuration: {
                      model: 'gpt-3.5-turbo',
                      model_params: {temp: 0.5},
                      messages: messages,
                  },
              });
              return response.content
          }

          async function helloWorld(lang: string, framework: string): Promise<string | null> {
              return llm([{role: 'user', content: `Write a hello world ${lang} in python using ${framework}.`}])
          }

          async function critiqueCode(code: string | null): Promise<string | null> {
              return llm([{role: 'user', content: `How can we improve this code: \n ${code}`}])
          }

          const chain = trace(
              'Chain', async (lang: string, framework: string): Promise<string | null> => {
                  return await critiqueCode(await helloWorld(lang, framework));
              },
          );

          async function main(): Promise<string | null> {
              return await chain('Python', 'FastAPI')
          }
          ```
        </CodeGroup>
      </Tab>

      <Tab title="Curl">
        Replace `$PAREA_API_KEY` with your API key.

        ```bash theme={null}
        curl 'https://parea-ai-backend-us-9ac16cdbc7a7b006.onporter.run/api/parea/v1/completion' \
        -H 'Content-Type: application/json' \
        -H 'x-api-key: $PAREA_API_KEY' \
        -d '{
            "llm_configuration": {
                "model": "gpt-3.5-turbo",
                "model_params": {"temp": 0.5},
                "messages": [
                    {
                        "role": "user",
                        "content": "Write a hello world program in Python using FastAPI."
                    }
                ]
            }
        }'
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="View Logs">
    Now you can view your trace logs on the [Logs](https://app.parea.ai/logs) page. You will see a table of your logs, and any chains will be expandable. The log table supports search, filtering, and sorting.

    <img src="https://mintcdn.com/pareaai/lIjZ3aMZeTkxaUc8/welcome/trace-log-table.png?fit=max&auto=format&n=lIjZ3aMZeTkxaUc8&q=85&s=66f393f5944a9b311dbb0a7a05aba2e0" alt="trace-log-table" width="1830" height="452" data-path="welcome/trace-log-table.png" />

    If you click a log, it will open the detailed trace view. Here, you can step through each span and view inputs, outputs, messages, metadata, and other key metrics associated with a given trace.

    You can also add these traces to a test collection to test new prompts on historical inputs or open the trace in the Playground to iterate on the example.

    <img src="https://mintcdn.com/pareaai/lIjZ3aMZeTkxaUc8/welcome/detailed-trace-log.png?fit=max&auto=format&n=lIjZ3aMZeTkxaUc8&q=85&s=8670480991d6fcb1e40b949b75589de1" alt="detailed-trace-log" width="1860" height="839" data-path="welcome/detailed-trace-log.png" />
  </Step>
</Steps>

## What's Next?

Explore our cookbooks for more examples on how to use Parea's SDKs.

* Python
  * [Cookbooks](https://github.com/parea-ai/parea-sdk-py/tree/6e8aabbf998b31bbba818a50c0d5e6bf3bb90624/cookbook)
* Typescript
  * [Cookbooks](https://github.com/parea-ai/parea-sdk-ts/tree/58641d0117d935f27818138ff89a107c13034503/cookbook)

Learn how to use evaluation metrics to run experiments.

* [Experiments](/evaluation/overview)
