How to beginner · 3 min read

File search supported file types in OpenAI

Quick answer
OpenAI file search supports text-based files including .txt, .json, .csv, and .pdf (text-extractable). You upload these files via the OpenAI API and then perform search queries on their content using the file.search endpoint.

PREREQUISITES

  • Python 3.8+
  • OpenAI API key (free tier works)
  • pip install openai>=1.0

Setup

Install the official OpenAI Python SDK and set your API key as an environment variable.

bash
pip install openai>=1.0

Step by step

Upload a supported file and perform a search query on its contents using the OpenAI Python SDK v1.

python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

# Upload a text file (e.g., .txt, .json, .csv, or text-extractable .pdf)
with open("example.txt", "rb") as f:
    upload_response = client.files.create(file=f, purpose="search")
file_id = upload_response.id

# Search the uploaded file for a query
search_response = client.files.search(
    file=file_id,
    query="search term",
    max_rerank=5
)

# Print top search results
for result in search_response.data:
    print(f"Score: {result.score}, Text: {result.text}")
output
Score: 0.95, Text: Relevant excerpt containing 'search term'
Score: 0.87, Text: Another relevant excerpt

Common variations

  • Use .jsonl files for structured data search.
  • PDF files must contain extractable text; scanned images are not supported.
  • Use different models for search ranking by specifying model parameter in files.search.

Troubleshooting

  • If upload fails, verify file format and size limits (max 100MB).
  • If search returns no results, check that the file contains searchable text.
  • Ensure your API key has file access permissions enabled.

Key Takeaways

  • OpenAI file search supports text-based files like .txt, .json, .csv, and text-extractable .pdf.
  • Upload files with purpose='search' to enable search queries on their content.
  • Use the OpenAI Python SDK v1 with environment variable API keys for secure integration.
Verified 2026-04 · gpt-4o, gpt-4o-mini
Verify ↗