# OpenAI Python SDK

> Use OpenAI's Python SDK to integrate with Helicone to log your OpenAI usage.

import { strings } from "/snippets/strings.mdx";
import LegacyWarning from "/snippets/legacy-provider-warning.mdx";

<LegacyWarning />

## {strings.howToIntegrate}

<video width="100%" controls autoplay loop>
  <source
    src="https://marketing-assets-helicone.s3.us-west-2.amazonaws.com/Helicone+OpenAI+Python+Tutorial.mp4"
    type="video/mp4"
  />
  Your browser does not support the video tag.
</video>

<Steps>
  <Step title={strings.generateKey}>
    <div dangerouslySetInnerHTML={{ __html: strings.generateKeyInstructions }} />
  </Step>

  <Step title={strings.setApiKey}>
    ```bash
    HELICONE_API_KEY=<your-helicone-api-key>
    OPENAI_API_KEY=<your-openai-api-key>
    ```
  </Step>

  <Step title={strings.modifyBasePath}>
    <CodeGroup>
      ```python OpenAI v1+
      from openai import OpenAI
      from dotenv import load_dotenv
      import os

      load_dotenv()

      helicone_api_key = os.getenv("HELICONE_API_KEY")
      openai_api_key = os.getenv("OPENAI_API_KEY")

      client = OpenAI(
        api_key=openai_api_key,
        base_url="https://oai.helicone.ai/v1",
        default_headers={
          "Helicone-Auth": f"Bearer {helicone_api_key}"
        }
      )
      ```
    </CodeGroup>
  </Step>

  <Step title={strings.useTheSDK("OpenAI")}>
    ```python
    chat_completion = client.chat.completions.create(
      model="gpt-4o-mini",
      messages=[{"role": "user", "content": "What is the meaning of life?"}]
    )

    print(chat_completion.choices[0].message.content)
    ```
  </Step>

  <Step title={strings.verifyInHelicone}>
    <div dangerouslySetInnerHTML={{ __html: strings.verifyInHeliconeDesciption("OpenAI") }} />
  </Step>
</Steps>

## {strings.relatedGuides}

<CardGroup cols={2}>
  <Card
    title="Building a chatbot with OpenAI structured outputs"
    icon="lightbulb"
    href="/guides/cookbooks/openai-structured-outputs"
    iconType="light"
    vertical
  >
    {strings.chatbotCookbookDescription}
  </Card>
  <Card
    title="How to Prompt Thinking Models Effectively"
    icon="arrows-rotate"
    href="/guides/cookbooks/prompt-thinking-models"
    iconType="light"
    vertical
  >
    {strings.howToPromptThinkingModelsCookbookDescription}
  </Card>
</CardGroup>
