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

# OpenAI Integration

> The easiest way to add file operations to your OpenAI applications. Change one import, keep everything else.

## How It Works

1. **Replace the import** - Change from `openai` to `@openfiles-ai/sdk/openai`
2. **Add your OpenFiles key** - Include your OpenFiles API key
3. **That's it** - Your AI can now create and manage files automatically

## Features

* ✅ **100% OpenAI Compatible** - All OpenAI features still work
* ✅ **Automatic File Operations** - No manual tool handling
* ✅ **Zero Learning Curve** - Use your existing OpenAI knowledge
* ✅ **TypeScript & Python** - Full support for both

## Installation

Refer to the [SDK Overview](/guides/overview#import-paths) for installation instructions.

## Two Simple Changes

<CodeGroup>
  ```typescript TypeScript theme={null}
  // 1. Change the import
  import OpenAI from '@openfiles-ai/sdk/openai' // ← Changed from 'openai'

  const ai = new OpenAI({
    apiKey: process.env.OPENAI_API_KEY,        // ← Same as before
    openFilesApiKey: process.env.OPENFILES_API_KEY // ← Add this line
  })

  // Everything else stays exactly the same
  const response = await ai.chat.completions.create({
    model: 'gpt-4',
    messages: [{
      role: 'user',
      content: 'Create a shopping list for making chocolate chip cookies and save it as shopping-list.md'
    }]
  })

  console.log(response.choices[0].message.content)
  // "I've created a shopping list with all the ingredients 
  // you'll need for chocolate chip cookies..."
  ```

  ```python Python theme={null}
  # 1. Change the import
  from openfiles_ai import OpenAI  # ← Changed from 'openai'
  import os
  import asyncio

  async def main():
      ai = OpenAI(
          api_key=os.getenv('OPENAI_API_KEY'),        # ← Same as before
          openfiles_api_key=os.getenv('OPENFILES_API_KEY') # ← Add this line
      )

      # Everything else stays exactly the same
      response = await ai.chat.completions.create(
          model='gpt-4',
          messages=[{
              'role': 'user',
              'content': 'Create a shopping list for making chocolate chip cookies and save it as shopping-list.md'
          }]
      )

      print(response.choices[0].message.content)
      # "I've created a shopping list with all the ingredients 
      # you'll need for chocolate chip cookies..."

  if __name__ == "__main__":
      asyncio.run(main())
  ```
</CodeGroup>

## What Gets Added

When you use our OpenAI replacement, we automatically:

1. **Inject file operation tools** into your requests
2. **Execute file operations** when the AI calls them
3. **Return results** seamlessly to the AI
4. **Continue the conversation** naturally

## Supported Operations

Your AI can automatically:

* **Create files** - "Write a grocery list for tonight's dinner party"
* **Read files** - "What's in my shopping-list.md file?"
* **Edit files** - "Add butter to the shopping list"
* **List files** - "Show me all my recipe files"
* **Append content** - "Add a new item to my todo list"
* **Overwrite files** - "Replace my old travel itinerary"
* **Get metadata** - "How large is the vacation-photos.txt?"
* **Access versions** - "Show me previous versions of my budget spreadsheet"

## File Organization

Use `basePath` to organize files:

<CodeGroup>
  ```typescript TypeScript theme={null}
  const ai = new OpenAI({
    apiKey: 'sk-...',
    openFilesApiKey: 'oa-...',
    basePath: 'projects/website'
  })
  // All files created under 'projects/website/'
  ```

  ```python Python theme={null}
  ai = OpenAI(
      api_key='sk-...',
      openfiles_api_key='oa-...',
      base_path='projects/website'
  )
  # All files created under 'projects/website/'
  ```
</CodeGroup>

## Monitoring

Add callbacks to monitor file operations:

<CodeGroup>
  ```typescript TypeScript theme={null}
  const ai = new OpenAI({
    apiKey: 'sk-...',
    openFilesApiKey: 'oa-...',
    onFileOperation: (op) => {
      console.log(`File operation: ${op.action} ${op.path}`)
    }
  })
  ```

  ```python Python theme={null}
  def on_file_operation(op):
      print(f"File operation: {op.action} {op.path}")

  ai = OpenAI(
      api_key='sk-...',
      openfiles_api_key='oa-...',
      on_file_operation=on_file_operation
  )
  ```
</CodeGroup>

## Compatibility

* ✅ Chat completions (text-based conversations)
* ✅ All OpenAI chat models (GPT-3.5, GPT-4, etc.)
* ✅ Function calling and tool use
* 🔜 Streaming responses (coming soon)
* 🔜 Image inputs and vision models (coming soon)
* 🔜 Assistants API (coming soon)

## When to Use OpenAI Integration

**Choose OpenAI Integration when:**

* You're already using the OpenAI SDK
* You want the simplest possible setup
* You need automatic file operations with zero configuration
* You prefer a drop-in replacement approach

**Consider alternatives:**

* **[Tools Integration](/guides/tools-integration)** - If you're using multiple AI providers or want more control
* **[Core Client](/guides/core-client)** - If you need direct API access without AI dependencies

## Next Steps

<CardGroup cols={2}>
  <Card title="Examples" icon="github" href="/resources/examples">
    See real OpenAI integration examples
  </Card>

  <Card title="Tools Integration" icon="wrench" href="/guides/tools-integration">
    Use OpenFiles with Claude, Anthropic, and other AI providers
  </Card>
</CardGroup>
