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

# Langtrace Self-Hosting Configuration

> Learn how to use Langtrace SDK for Self-Hosted Setup

Install the dependencies

<CodeGroup>
  ```python Python theme={null}
  pip install langtrace-python-sdk openai
  ```

  ```javascript Javascript theme={null}
  npm i @langtrase/typescript-sdk openai
  ```
</CodeGroup>

For `typescript`, add a `package.json` as follows:

```json theme={null}
{
	"dependencies": {
		"@langtrase/typescript-sdk": "^3.3.2",
		"openai": "^4.50.0"
	}
}
```

Following are the parameters that you need to initialize the SDK:

<CodeGroup>
  ```python Python theme={null}
  from langtrace_python_sdk import langtrace
  langtrace.init(
    api_key="<YOUR API KEY>",
    api_host="http://localhost:3000/api/trace",
  )
  ```

  ```javascript Javascript theme={null}
  import * as Langtrace from "@langtrase/typescript-sdk";
  Langtrace.init({
  	api_key: "<YOUR API KEY>",
  	batch: false,
  	api_host: "http://localhost:3000/api/trace",
  });
  ```
</CodeGroup>

Here we are using `http://localhost:3000/api/trace` as the API host. You can replace it with your own DNS or IP address.

## Sample Code

Following is a ready-to-run code snippet that you can use to test the SDK with your local setup:

<Info>
  Make Sure to pip or npm install the required packages before running the code.
</Info>

<CodeGroup>
  ```python Python theme={null}
  from langtrace_python_sdk import langtrace
  from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span

  from openai import OpenAI

  langtrace.init(
      api_key="<YOUR API KEY>",
      api_host="http://localhost:3000/api/trace",
  )

  @with_langtrace_root_span()
  def example():
      client = OpenAI()
      response = client.chat.completions.create(
          model="gpt-3.5-turbo",
          messages=[
              {
                  "role": "system",
                  "content": "How many states of matter are there?"
              }
          ],
      )
      print(response.choices[0].message.content)

  example()
  ```

  ```javascript Javascript theme={null}
  import * as Langtrace from "@langtrase/typescript-sdk";
  import OpenAI from "openai";
  Langtrace.init({
  	api_key: "<YOUR API KEY>",
  	batch: false,
  	api_host: "http://localhost:3000/api/trace",
  	instrumentations: {
  		openai: OpenAI,
  	},
  });
  const openai = new OpenAI();

  async function example() {
  	const completion = await openai.chat.completions.create({
  		model: "gpt-3.5-turbo",
  		messages: [
  			{
  				role: "system",
  				content: "How many states of matter are there?",
  			},
  		],
  	});
  	console.log(completion.choices[0]);
  }

  example().then(() => {
  	console.log("done");
  });
  ```
</CodeGroup>

Run the scripts as follows

<CodeGroup>
  ```python main.py theme={null}
  export OPENAI_API_KEY="<YOUR OPENAI API KEY>"
  python main.py
  ```

  ```javascript main.js theme={null}
  export OPENAI_API_KEY="<YOUR OPENAI API KEY>"
  node main.js
  ```
</CodeGroup>

<Note>
  For Typescript to work, you will have to add the following line in
  `package.json` file. `json "type": "module" `
</Note>
