OpenAI
Generate chat completions, embeddings, and manage Assistants threads.
Authentication
| Type | Default | Details |
|---|---|---|
api_key | ✅ | API key (sk-... or sk-proj-...) sent as Authorization: Bearer |
Optional organization ID can be passed to set the OpenAI-Organization header.
Endpoints
| Path | Risk | Description |
|---|---|---|
chat.completions.create | write | Generate a chat completion (consumes tokens — metered). |
embeddings.create | write | Generate vector embeddings for text (consumes tokens). |
threads.create | write | Create a new Assistants thread. |
threads.get | read | Get an Assistants thread. |
threads.delete | destructive | Delete an Assistants thread and all its messages. |
messages.create | write | Append a user message to a thread. |
messages.list | read | List messages on a thread. |
runs.create | write | Create a run on a thread (kicks off the assistant). |
runs.get | read | Poll a run's status. |
runs.cancel | write | Cancel an in-progress run. |
chat.completions.create
Generate a chat completion.
Input:
| Field | Type | Required | Description |
|---|---|---|---|
model | string | ✅ | Model ID (e.g. gpt-4o) |
messages | array | ✅ | Array of { role, content, ... } messages |
temperature | number | Sampling temperature (0–2) | |
max_tokens | number | Max tokens to generate | |
tools | array | Function tools definitions | |
tool_choice | string | object | auto, none, required, or { type: "function", function: { name } } | |
response_format | object | { type: "text" | "json_object" } |
Output: ChatCompletion
embeddings.create
Generate text embeddings.
Input:
| Field | Type | Required | Description |
|---|---|---|---|
model | string | ✅ | Model ID (e.g. text-embedding-3-small) |
input | string | string[] | ✅ | Text to embed |
dimensions | number | Output dimensions | |
encoding_format | enum | float (default) or base64 |
Output: { object: "list"; data: Embedding[]; model: string; usage: { prompt_tokens: number; total_tokens: number } }
threads.create
Create a new Assistants thread.
Input:
| Field | Type | Description |
|---|---|---|
messages | array | Initial messages: { role: "user"; content: string }[] |
metadata | object | Key-value metadata |
Output: AssistantThread
threads.get
Get a thread by ID.
Input:
| Field | Type | Required | Description |
|---|---|---|---|
threadId | string | ✅ | Thread ID |
Output: AssistantThread
threads.delete
Delete a thread and all its messages.
Input:
| Field | Type | Required | Description |
|---|---|---|---|
threadId | string | ✅ | Thread ID |
Output: { id: string; object: "thread.deleted"; deleted: true }
messages.create
Add a message to a thread.
Input:
| Field | Type | Required | Description |
|---|---|---|---|
threadId | string | ✅ | Thread ID |
role | enum | ✅ | user |
content | string | ✅ | Message text |
metadata | object | Key-value metadata |
Output: AssistantMessage
messages.list
List messages in a thread.
Input:
| Field | Type | Description |
|---|---|---|
threadId | string | ✅ Thread ID |
limit | number | Max results |
order | enum | asc or desc |
after | string | Pagination cursor |
Output: { object: "list"; data: AssistantMessage[]; has_more: boolean }
runs.create
Create a run to process a thread.
Input:
| Field | Type | Required | Description |
|---|---|---|---|
threadId | string | ✅ | Thread ID |
assistant_id | string | ✅ | Assistant ID |
instructions | string | Override instructions | |
additional_instructions | string | Additional instructions | |
tools | array | Tools for this run | |
metadata | object | Key-value metadata |
Output: AssistantRun
runs.get
Poll a run's status.
Input:
| Field | Type | Required | Description |
|---|---|---|---|
threadId | string | ✅ | Thread ID |
runId | string | ✅ | Run ID |
Output: AssistantRun
runs.cancel
Cancel an in-progress run.
Input:
| Field | Type | Required | Description |
|---|---|---|---|
threadId | string | ✅ | Thread ID |
runId | string | ✅ | Run ID |
Output: AssistantRun
Usage
import { createFabric } from "@fabricorg/integrations";
import { openai } from "@fabricorg/integrations/plugins";
const fabric = createFabric({
plugins: [openai({ apiKey: process.env.OPENAI_API_KEY })],
});
// Chat completion
const completion = await fabric.openai.api.chat.completions.create({
model: "gpt-4o",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What is the capital of France?" },
],
});
// Embeddings
const { data: embeddings } = await fabric.openai.api.embeddings.create({
model: "text-embedding-3-small",
input: "The quick brown fox",
});
// Assistants flow
const thread = await fabric.openai.api.threads.create({
messages: [{ role: "user", content: "Explain quantum computing" }],
});
const run = await fabric.openai.api.runs.create({
threadId: thread.id,
assistant_id: "asst_abc123",
});
// Poll until complete
let status = run.status;
while (status === "queued" || status === "in_progress") {
await new Promise((r) => setTimeout(r, 1000));
const updated = await fabric.openai.api.runs.get({
threadId: thread.id,
runId: run.id,
});
status = updated.status;
}Webhooks
OpenAI does not support webhooks. The Assistants API requires polling (runs.get) to check run status.
Types
interface ChatCompletionMessage {
role: "system" | "user" | "assistant" | "tool";
content: string | null;
name?: string;
tool_call_id?: string;
tool_calls?: Array<{
id: string;
type: "function";
function: { name: string; arguments: string };
}>;
}
interface ChatCompletion {
id: string;
object: "chat.completion";
created: number;
model: string;
choices: Array<{
index: number;
message: ChatCompletionMessage;
finish_reason: string | null;
}>;
usage?: {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
};
}
interface Embedding {
object: "embedding";
embedding: number[];
index: number;
}
interface AssistantThread {
id: string;
object: "thread";
created_at: number;
metadata?: Record<string, string>;
}
interface AssistantMessage {
id: string;
object: "thread.message";
thread_id: string;
role: "user" | "assistant";
content: Array<{ type: string; text?: { value: string } }>;
created_at: number;
}
interface AssistantRun {
id: string;
object: "thread.run";
thread_id: string;
assistant_id: string;
status: "queued" | "in_progress" | "requires_action" | "cancelling" | "cancelled" | "failed" | "completed" | "expired";
created_at: number;
required_action?: {
type: "submit_tool_outputs";
submit_tool_outputs: {
tool_calls: Array<{
id: string;
type: "function";
function: { name: string; arguments: string };
}>;
};
};
}