---
name: "openai-assistants-v2-threads"
description: "Build stateful conversational AI applications with OpenAI Assistants API v2."
metadata:
  author: "OpenAI"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "create openai assistant thread"
  - "stream assistant run"
  - "attach file_search to assistant"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# OpenAI Assistants API v2 Threads & Streaming

Implements OpenAI Assistants API: persistent Threads, Messages, Runs, tool attachments (file_search, code_interpreter), and real-time streaming with AssistantEventHandler.

## When to Invoke
Invoke this skill whenever you need to:
- create openai assistant thread
- stream assistant run
- attach file_search to assistant

## Execution SOP & Rules
1. Create persistent threads with client.beta.threads.create() to manage dialogue state automatically.
2. Use client.beta.threads.runs.stream() with custom AssistantEventHandler for instant token streaming.
3. Submit tool outputs via client.beta.threads.runs.submit_tool_outputs_stream() when actions are requested.
4. Poll run status or handle webhooks to detect run completion, failures, and cancellations.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
