### API Key Example Source: https://platform.apodex.ai/docs Your API key will look like this. Keep it secure! ```text # Your API key will look like this: sk_live_1234567890abcdef... ``` -------------------------------- ### Fetch Response Snapshot (cURL) Source: https://platform.apodex.ai/docs/responses-api Example of retrieving a full response object snapshot using a GET request to the /v1/responses/:id endpoint. ```shell curl https://api.apodex.ai/v1/responses/resp_ \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### SSE Stream Lifecycle Example Source: https://platform.apodex.ai/docs/streaming Illustrates the sequence of chunks emitted during a streaming response, from role assignment to the final [DONE] signal. ```text 1. role chunk {"delta": {"role": "assistant"}} 2. reasoning chunks {"delta": {"reasoning_steps": [...]}} (thinking, tool use) 3. content chunks {"delta": {"content": "..."}} (final answer) 4. finish chunk {"delta": {}, "finish_reason": "stop", "usage": {...}} 5. [DONE] signal data: [DONE] ``` -------------------------------- ### SSE Chunk Format Example Source: https://platform.apodex.ai/docs/streaming Demonstrates the structure of Server-Sent Events (SSE) data chunks, including content and final usage information. ```text data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","model":"apodex-1-0-deepresearch-mini","created":1712345678,"choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]} data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","model":"apodex-1-0-deepresearch-mini","created":1712345678,"choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":10,"completion_tokens":100,"total_tokens":110}} data: [DONE] ``` -------------------------------- ### SSE Heartbeat Comment Example Source: https://platform.apodex.ai/docs/streaming Illustrates an SSE comment line used as a keep-alive heartbeat to prevent timeouts during idle periods. ```text : heartbeat ``` -------------------------------- ### SSE Event Stream Response Example Source: https://platform.apodex.ai/docs/responses-api Illustrates the structure of Server-Sent Events (SSE) frames received from the /v1/responses endpoint during a streaming request. ```text event: response.created data: {"type":"response.created","sequence_number":1,"response":{"id":"resp_","status":"in_progress",...}} event: response.in_progress data: {"type":"response.in_progress","sequence_number":2,...} event: response.output_item.added data: {"type":"response.output_item.added","sequence_number":3,"output_index":0,"item":{"id":"rs_","type":"reasoning","summary":[]}} event: response.reasoning_text.delta data: {"type":"response.reasoning_text.delta","sequence_number":4,"item_id":"rs_","output_index":0,"content_index":0,"delta":"Thinking about ..."} ... (more reasoning + optional tool_call output items) ... event: response.output_item.added data: {"type":"response.output_item.added","sequence_number":N,"output_index":1,"item":{"id":"msg_","type":"message","role":"assistant","content":[]}} event: response.output_text.delta data: {"type":"response.output_text.delta","sequence_number":N+1,"item_id":"msg_","output_index":1,"content_index":0,"delta":"Recent advances ..."} event: response.output_text.done data: {"type":"response.output_text.done","sequence_number":N+M,...} event: response.completed data: {"type":"response.completed","sequence_number":N+M+1,"response":{"id":"resp_","status":"completed","output":[...],"usage":{...}}} ``` -------------------------------- ### Delta Object Example: Role Assignment Source: https://platform.apodex.ai/docs/streaming Shows the structure of a delta object when assigning a role to the assistant. ```json {"delta": {"role": "assistant"}} ``` -------------------------------- ### List Models API Response Source: https://platform.apodex.ai/docs/chat-completions Example JSON response when listing available models via the API. Shows model IDs, context lengths, and other metadata. ```json { "object": "list", "data": [ { "id": "apodex-1-0-deepresearch-h", "object": "model", "created": 1700000000, "owned_by": "apodex", "context_length": 131072, "max_completion_tokens": 262144 }, { "id": "apodex-1-0-deepresearch", "object": "model", "created": 1700000000, "owned_by": "apodex", "context_length": 262144, "max_completion_tokens": 16384 }, { "id": "apodex-1-0-deepresearch-mini", "object": "model", "created": 1700000000, "owned_by": "apodex", "context_length": 262144, "max_completion_tokens": 16384 } ] } ``` -------------------------------- ### Resume SSE Stream (cURL) Source: https://platform.apodex.ai/docs/responses-api Example of resuming an SSE stream from a specific sequence number using the ?stream=true&after=SEQ query parameter. ```shell curl https://api.apodex.ai/v1/responses/resp_?stream=true&after=SEQ \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### GET /v1/responses Source: https://platform.apodex.ai/docs/responses-api Lists the authenticated user's recent responses. This endpoint returns lifecycle metadata only and does not include output. To fetch individual responses with their output, use GET /v1/responses/:id. ```APIDOC ## GET /v1/responses ### Description List the authenticated user's recent responses. Lifecycle metadata only — no output[]; fetch individual responses via GET /v1/responses/:id. ### Method GET ### Endpoint /v1/responses ### Headers - **Authorization** (string) - Required - Your Apodex API key (`Bearer YOUR_API_KEY`) ### Response #### Success Response (200) - A list of response metadata objects. ``` -------------------------------- ### Handle SSE Stream Response Source: https://platform.apodex.ai/docs The response streams as SSE by default. Parse SSE lines to get reasoning steps and content. ```text # Stream is the default. Parse SSE lines: data: {"choices":[{"delta":{"content":"Hello!"}}]} data: [DONE] ``` -------------------------------- ### Submit Response via SSE Stream (cURL) Source: https://platform.apodex.ai/docs/responses-api Example of submitting a request to the /v1/responses endpoint using cURL to receive a Server-Sent Events (SSE) stream. ```shell curl -N -X POST https://api.apodex.ai/v1/responses \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "apodex-1-0-deepresearch-mini", "input": "Summarize the recent advances in fusion energy." }' ``` -------------------------------- ### POST /v1/responses Source: https://platform.apodex.ai/docs/responses-api Creates a response. By default, it streams events via SSE. If stream=false, it blocks until the workflow completes and returns the full Response JSON. If background=true, the call returns immediately, and the result can be fetched later via GET /v1/responses/:id. ```APIDOC ## POST /v1/responses ### Description Creates a response. With stream=true (default) the response body is an SSE event stream; with stream=false the connection blocks until the workflow finishes and returns the full Response JSON. With background=true the call returns immediately and you fetch the result via GET /v1/responses/:id. ### Method POST ### Endpoint /v1/responses ### Headers - **Authorization** (string) - Required - Your Apodex API key (`Bearer YOUR_API_KEY`) - **Content-Type** (string) - Required - Must be application/json (`application/json`) ### Parameters #### Query Parameters - **model** (string) - Required - Model ID, e.g. "apodex-1-0-deepresearch-mini". - **input** (string | array) - Required - A user prompt as a plain string, or an array of {type, role, content} input items. - **stream** (boolean) - Whether to stream events via SSE. Defaults to true. - **background** (boolean) - If true, returns the Response object immediately (status="in_progress") without holding a connection. Use GET /v1/responses/:id (or ?stream=true to resume the SSE stream) to fetch the result later. Mutually exclusive with stream=true. - **max_output_tokens** (integer) - Maximum number of tokens to generate. - **temperature** (number) - Sampling temperature. - **metadata** (object) - Free-form key-value metadata stored with the response. ### Request Example ```json { "model": "apodex-1-0-deepresearch-mini", "input": "Summarize the recent advances in fusion energy." } ``` ### Response #### Success Response (200) - **event**: response.created - **data**: {"type":"response.created","sequence_number":1,"response":{"id":"resp_","status":"in_progress",...}} - **event**: response.output_text.delta - **data**: {"type":"response.output_text.delta","sequence_number":4,"item_id":"rs_","output_index":0,"content_index":0,"delta":"Thinking about ..."} - **event**: response.completed - **data**: {"type":"response.completed","sequence_number":N+M+1,"response":{"id":"resp_","status":"completed","output":[...],"usage":{...}}} #### Response Example (Streaming SSE events as described above, or a JSON snapshot if stream=false) ``` -------------------------------- ### Non-Streaming Chat Completion Response Source: https://platform.apodex.ai/docs/chat-completions Example of a non-streaming response from the Chat Completions API. Includes completion details and token usage. ```json { "id": "chatcmpl-abc123", "object": "chat.completion", "created": 1712345678, "model": "apodex-1-0-deepresearch-mini", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Here are the latest trends in AI..." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 12, "completion_tokens": 256, "total_tokens": 268 } } ``` -------------------------------- ### GET /v1/responses/:id Source: https://platform.apodex.ai/docs/responses-api Fetches a Response by its ID. By default, it returns a full Response object snapshot reconstructed from the workflow's event stream. With ?stream=true, it opens an SSE stream that replays the event history and continues live until the workflow terminates. ```APIDOC ## GET /v1/responses/:id ### Description Fetch a Response by id. Default: returns the full Response object snapshot reconstructed from the workflow's event stream. With ?stream=true: opens an SSE stream that replays the entire event history through the translator and continues live until the workflow terminates — clients that lost their connection mid-stream can reconnect with ?stream=true&after=SEQ to skip events they already saw. ### Method GET ### Endpoint /v1/responses/:id ### Headers - **Authorization** (string) - Required - Your Apodex API key (`Bearer YOUR_API_KEY`) ### Parameters #### Query Parameters - **stream** (boolean) - If true, returns SSE event stream (replay + live). If absent or false, returns the JSON snapshot. - **after** (integer) - Only meaningful with stream=true. Skip events whose sequence_number is ≤ this value. Use to resume a stream where you left off. ### Response #### Success Response (200) - **id** (string) - The response ID. - **object** (string) - The object type, always "response". - **status** (string) - The status of the response (e.g., "completed"). - **model** (string) - The model ID used. - **output** (array) - The reconstructed output of the response. - **usage** (object) - Usage statistics. #### Response Example ```json { "id": "resp_", "object": "response", "status": "completed", "model": "apodex-1-0-deepresearch-mini", "output": [...], "usage": {...} } ``` ``` -------------------------------- ### List Models via API Source: https://platform.apodex.ai/docs/chat-completions Retrieve a list of available models and their capabilities programmatically. Useful for clients that need to enumerate or check model capabilities at runtime. ```bash curl https://api.apodex.ai/v1/models \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### List Models Source: https://platform.apodex.ai/docs/chat-completions Retrieves a list of available models and their capabilities. Useful for clients to enumerate or check model capabilities at runtime. ```APIDOC ## GET /v1/models ### Description Retrieves a list of available models and their capabilities. ### Method GET ### Endpoint /v1/models ### Response #### Success Response (200) - **object** (string) - Type of the response, "list". - **data** (array) - An array of model objects. - **id** (string) - The model ID. - **object** (string) - Type of the object, "model". - **created** (integer) - Timestamp of model creation. - **owned_by** (string) - The organization that owns the model. - **context_length** (integer) - The maximum context length of the model. - **max_completion_tokens** (integer) - The maximum number of tokens the model can generate. ### Request Example ```bash curl https://api.apodex.ai/v1/models \ -H "Authorization: Bearer YOUR_API_KEY" ``` ``` -------------------------------- ### Chat Completions API Source: https://platform.apodex.ai/docs OpenAI-compatible chat completions with built-in reasoning, tool use, and streaming. ```APIDOC ## POST /v1/chat/completions ### Description Send a POST request to the Chat Completions endpoint. Works with any OpenAI-compatible client. ### Method POST ### Endpoint https://api.apodex.ai/v1/chat/completions ### Parameters #### Headers - **Authorization** (string) - Required - Bearer YOUR_API_KEY - **Content-Type** (string) - Required - application/json ### Request Body - **model** (string) - Required - The model to use for chat completions. - **messages** (array) - Required - An array of message objects, each with a role and content. - **role** (string) - Required - The role of the author of the message (e.g., "user", "assistant"). - **content** (string) - Required - The content of the message. ### Request Example ```json { "model": "apodex-1-0-deepresearch-mini", "messages": [ { "role": "user", "content": "Hello!" } ] } ``` ### Response #### Success Response (200) - **choices** (array) - An array of choices, each containing a delta with content. - **delta** (object) - The change in the assistant's response. - **content** (string) - The content of the message chunk. ``` -------------------------------- ### OpenAI SDK Streaming Chat Completions (JavaScript) Source: https://platform.apodex.ai/docs/streaming Consumes SSE streams from the Chat Completions API using the official OpenAI SDK in JavaScript. Handles content streaming and final finish reason/usage. ```javascript import OpenAI from 'openai'; const client = new OpenAI({ apiKey: process.env.APODEX_API_KEY, baseURL: 'https://api.apodex.ai/v1', }); const stream = await client.chat.completions.create({ model: 'apodex-1-0-deepresearch-mini', messages: [{ role: 'user', content: 'Hello' }], stream: true, }); for await (const chunk of stream) { const choice = chunk.choices[0]; const delta = choice.delta; // Final answer (token-by-token) if (delta?.content) { process.stdout.write(delta.content); } // Finish + usage (last chunk) if (choice.finish_reason) { console.log(`\nFinish: ${choice.finish_reason}`); if (chunk.usage) console.log('Usage:', chunk.usage); } } ``` -------------------------------- ### Create Chat Completion (cURL) Source: https://platform.apodex.ai/docs/chat-completions Send a conversation to the model and receive a completion using cURL. Supports streaming responses. ```bash curl -X POST https://api.apodex.ai/v1/chat/completions \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "apodex-1-0-deepresearch-mini", "messages": [ { "role": "user", "content": "What are the latest trends in AI?" } ], "stream": true }' ``` -------------------------------- ### Authenticate API Request with JavaScript Source: https://platform.apodex.ai/docs/authentication This JavaScript snippet shows how to authenticate API requests using environment variables for your API key. Ensure your API key is stored securely. ```javascript const response = await fetch('https://api.apodex.ai/v1/chat/completions', { method: 'POST', headers: { 'Authorization': `Bearer ${process.env.APODEX_API_KEY}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ messages: [{ role: 'user', content: 'Hello!' }] }) }); ``` -------------------------------- ### Authenticate API Request with cURL Source: https://platform.apodex.ai/docs/authentication Use this cURL command to authenticate your API requests by including your API key in the Authorization header. ```bash curl https://api.apodex.ai/v1/chat/completions \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" ``` -------------------------------- ### Create Chat Completion Source: https://platform.apodex.ai/docs/chat-completions Sends a conversation to the model and receives a completion. Supports streaming (SSE) and non-streaming modes. ```APIDOC ## POST /v1/chat/completions ### Description Sends a conversation to the model and receives a completion. Supports streaming (SSE) and non-streaming modes. ### Method POST ### Endpoint /v1/chat/completions ### Parameters #### Headers - **Authorization** (string) - Required. Your Apodex API key. Example: `Bearer YOUR_API_KEY` - **Content-Type** (string) - Required. Must be `application/json`. #### Request Body - **model** (string) - Required. Model ID to use, e.g. "apodex-1-0-deepresearch-mini". - **messages** (array) - Required. Array of message objects with "role" (system/user/assistant) and "content" fields. - **stream** (boolean) - Optional. Whether to stream the response via SSE. Defaults to true. - **max_tokens** (integer) - Optional. Maximum number of tokens to generate in the completion. - **mcp_servers** (array) - Optional. Array of MCP server configs ({name, url, headers?, access_token?, oauth?}) for external tool access. ### Request Example ```bash curl -X POST https://api.apodex.ai/v1/chat/completions \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d { "model": "apodex-1-0-deepresearch-mini", "messages": [ { "role": "user", "content": "What are the latest trends in AI?" } ], "stream": true } ``` ### Response #### Success Response (Non-Streaming) - **id** (string) - Unique identifier for the completion. - **object** (string) - Type of the object, "chat.completion". - **created** (integer) - Timestamp of completion creation. - **model** (string) - The model used for the completion. - **choices** (array) - An array of completion choices. - **index** (integer) - Index of the choice. - **message** (object) - The message content. - **role** (string) - Role of the message sender (assistant). - **content** (string) - The generated text content. - **finish_reason** (string) - The reason the model stopped generating tokens. - **usage** (object) - Token usage statistics. - **prompt_tokens** (integer) - Number of tokens in the prompt. - **completion_tokens** (integer) - Number of tokens in the completion. - **total_tokens** (integer) - Total tokens used. #### Response Example (Non-Streaming) ```json { "id": "chatcmpl-abc123", "object": "chat.completion", "created": 1712345678, "model": "apodex-1-0-deepresearch-mini", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Here are the latest trends in AI..." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 12, "completion_tokens": 256, "total_tokens": 268 } } ``` #### Response Example (Streaming) When `stream: true`, the response is delivered as Server-Sent Events (SSE). Each line is prefixed with `data: ` followed by a JSON chunk. The stream ends with `data: [DONE]`. **Phase 1: Reasoning** - `delta.reasoning_steps` (array) - Emits reasoning steps with `type` (e.g., thinking, web_search) and `content`. **Phase 2: Final Answer** - `delta.content` (string) - Streams the final answer token by token. ``` -------------------------------- ### Send a Chat Completions Request Source: https://platform.apodex.ai/docs Send a POST request to the Chat Completions endpoint. Works with any OpenAI-compatible client. ```curl curl -X POST https://api.apodex.ai/v1/chat/completions \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d {"model": "apodex-1-0-deepresearch-mini", "messages": [{"role": "user", "content": "Hello!"}]} ``` -------------------------------- ### Response Snapshot JSON Source: https://platform.apodex.ai/docs/responses-api The JSON structure returned when fetching a response snapshot (stream=false) from the /v1/responses/:id endpoint. ```json { "id": "resp_", "object": "response", "status": "completed", "model": "apodex-1-0-deepresearch-mini", "output": [...], "usage": {...} } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.