### Run Development Server Source: https://github.com/winfunc/deepreasoning/blob/main/frontend/README.md Use one of these commands to start the development server. Open http://localhost:3000 to view the application. ```bash npm run dev # or yarn dev # or pnpm dev # or bun dev ``` -------------------------------- ### Build and Run from Source Source: https://context7.com/winfunc/deepreasoning/llms.txt Steps to clone the repository, set up configuration, build the release binary, and run the application. Includes optional frontend setup. ```bash # Prerequisites: Rust 1.75+, DeepSeek API key, Anthropic API key git clone https://github.com/getasterisk/deepreasoning.git cd deepreasoning # Create config cat > config.toml << 'EOF' [server] host = "127.0.0.1" port = 1337 [pricing.deepseek] input_cache_hit_price = 0.14 input_cache_miss_price = 0.55 output_price = 2.19 [pricing.anthropic.claude_3_sonnet] input_price = 3.0 output_price = 15.0 cache_write_price = 3.75 cache_read_price = 0.30 [pricing.anthropic.claude_3_haiku] input_price = 0.80 output_price = 4.0 cache_write_price = 1.0 cache_read_price = 0.08 [pricing.anthropic.claude_3_opus] input_price = 15.0 output_price = 75.0 cache_write_price = 18.75 cache_read_price = 1.50 EOF # Build release binary cargo build --release # Run (set log level via RUST_LOG) RUST_LOG=deepreasoning=info ./target/release/deepreasoning # Frontend (optional) cd frontend npm install npm run dev # Starts Next.js on http://localhost:3000 ``` -------------------------------- ### Basic API Usage Example Source: https://github.com/winfunc/deepreasoning/blob/main/README.md Make a POST request to the DeepReasoning API with DeepSeek and Anthropic API keys. ```python import requests response = requests.post( "http://127.0.0.1:1337/", headers={ "X-DeepSeek-API-Token": "", "X-Anthropic-API-Token": "" }, json={ "messages": [ {"role": "user", "content": "How many 'r's in the word 'strawberry'?"} ] } ) print(response.json()) ``` -------------------------------- ### Clone DeepReasoning Repository Source: https://github.com/winfunc/deepreasoning/blob/main/README.md Clone the project repository to get started. Requires Git. ```bash git clone https://github.com/getasterisk/deepreasoning.git cd deepreasoning ``` -------------------------------- ### API Configuration Options Source: https://github.com/winfunc/deepreasoning/blob/main/README.md Example JSON structure for configuring API requests, including stream, verbose, system prompts, messages, and provider-specific configurations. ```json { "stream": false, "verbose": false, "system": "Optional system prompt", "messages": [...], "deepseek_config": { "headers": {}, "body": {} }, "anthropic_config": { "headers": {}, "body": {} } } ``` -------------------------------- ### cURL Example: Missing DeepSeek API Key Source: https://context7.com/winfunc/deepreasoning/llms.txt Demonstrates how to make a POST request using cURL and the expected error response when the 'X-DeepSeek-API-Token' header is missing. ```bash # Missing DeepSeek token: curl -X POST http://127.0.0.1:1337/ \ -H "Content-Type: application/json" \ -H "X-Anthropic-API-Token: YOUR_ANTHROPIC_KEY" \ -d '{"messages": [{"role": "user", "content": "Hello"}]}' # Response (HTTP 400): # { # "error": { # "message": "Missing required header: X-DeepSeek-API-Token", # "type": "missing_header", # "param": "X-DeepSeek-API-Token" # } # } ``` -------------------------------- ### Python Streaming Example Source: https://github.com/winfunc/deepreasoning/blob/main/README.md Demonstrates how to stream responses from the API using Python's httpx library. Ensure you have your DeepSeek and Anthropic API keys configured. ```python import asyncio import json import httpx async def stream_response(): async with httpx.AsyncClient() as client: async with client.stream( "POST", "http://127.0.0.1:1337/", headers={ "X-DeepSeek-API-Token": "", "X-Anthropic-API-Token": "" }, json={ "stream": True, "messages": [ {"role": "user", "content": "How many 'r's in the word 'strawberry'?"} ] } ) as response: response.raise_for_status() async for line in response.aiter_lines(): if line: if line.startswith('data: '): data = line[6:] try: parsed_data = json.loads(data) if 'content' in parsed_data: content = parsed_data.get('content', '')[0]['text'] print(content, end='',flush=True) else: print(data, flush=True) except json.JSONDecodeError: pass if __name__ == "__main__": asyncio.run(stream_response()) ``` -------------------------------- ### cURL Example: Duplicate System Prompt Source: https://context7.com/winfunc/deepreasoning/llms.txt Illustrates a cURL request that triggers an HTTP 400 error due to providing a system prompt in both the root level and the messages array. Shows the expected error response. ```bash # Duplicate system prompt (both root-level and in messages array): curl -X POST http://127.0.0.1:1337/ \ -H "Content-Type: application/json" \ -H "X-DeepSeek-API-Token: KEY" \ -H "X-Anthropic-API-Token: KEY" \ -d '{ "system": "Be helpful.", "messages": [ {"role": "system", "content": "Be concise."}, {"role": "user", "content": "Hi"} ] }' # Response (HTTP 400): # { # "error": { # "message": "System prompt can only be provided once, either in root or messages array", # "type": "invalid_system_prompt" # } # } ``` -------------------------------- ### Stream Chat Completion with SSE in Python Source: https://context7.com/winfunc/deepreasoning/llms.txt Use this snippet to stream chat completions from the API using Server-Sent Events. Ensure you have the httpx library installed and replace placeholder API keys. ```python import asyncio, json, httpx async def stream_deepreasoning(): async with httpx.AsyncClient(timeout=120) as client: async with client.stream( "POST", "http://127.0.0.1:1337/", headers={ "X-DeepSeek-API-Token": "YOUR_DEEPSEEK_KEY", "X-Anthropic-API-Token": "YOUR_ANTHROPIC_KEY", }, json={ "stream": True, "messages": [ {"role": "user", "content": "Write a Python quicksort implementation."} ], }, ) as response: response.raise_for_status() async for line in response.aiter_lines(): if not line: continue # SSE format: "event: \ndata: " # httpx aiter_lines yields individual lines if line.startswith("data: "): payload = json.loads(line[6:]) event_type = payload.get("type") if event_type == "start": print(f"[Stream started at {payload['created']}]") elif event_type == "content": for block in payload.get("content", []): # text = full block, text_delta = incremental chunk print(block["text"], end="", flush=True) elif event_type == "usage": u = payload["usage"] print(f"\n\n[Total cost: {u['total_cost']}]") print(f" DeepSeek: {u['deepseek_usage']['total_tokens']} tokens ({u['deepseek_usage']['total_cost']})") print(f" Anthropic: {u['anthropic_usage']['total_tokens']} tokens ({u['anthropic_usage']['total_cost']})") elif event_type == "done": print("\n[Stream complete]") elif event_type == "error": print(f"\n[Error {payload['code']}]: {payload['message']}") asyncio.run(stream_deepreasoning()) ``` -------------------------------- ### Chat Completion (Streaming via SSE) Source: https://context7.com/winfunc/deepreasoning/llms.txt This endpoint enables chat completions with streaming support using Server-Sent Events (SSE). By setting `"stream": true`, the API returns events like `start`, `content`, `usage`, `done`, and `error`. ```APIDOC ## POST / — Chat Completion (Streaming via SSE) ### Description Setting `"stream": true` switches the endpoint to Server-Sent Events mode. The stream emits a `start` event, then a series of `content` events (first streaming the DeepSeek reasoning deltas inside `` tags, then Claude's response deltas), followed by a `usage` event with final token counts and costs, and a terminal `done` event. Errors during streaming are delivered as `error` events. ### Method POST ### Endpoint / ### Parameters #### Query Parameters - **stream** (boolean) - Optional - If true, enables Server-Sent Events streaming. #### Request Body - **stream** (boolean) - Required - Enables or disables streaming. - **verbose** (boolean) - Optional - If true, includes raw upstream API responses for debugging. - **system** (string) - Optional - A system prompt to guide the AI's behavior. Mutually exclusive with a system role in `messages`. - **messages** (array) - Required - An array of message objects, each with a `role` (user, assistant, or system) and `content`. - **deepseek_config** (object) - Optional - Configuration for the DeepSeek provider. - **headers** (object) - Optional - Custom headers for the DeepSeek request. - **body** (object) - Optional - Request body parameters for DeepSeek. - **model** (string) - Optional - The DeepSeek model to use (e.g., `deepseek-reasoner`). - **max_tokens** (integer) - Optional - The maximum number of tokens to generate. - **temperature** (number) - Optional - Controls randomness. Higher values mean more random output. - **anthropic_config** (object) - Optional - Configuration for the Anthropic provider. - **headers** (object) - Optional - Custom headers for the Anthropic request. - **body** (object) - Optional - Request body parameters for Anthropic. - **model** (string) - Optional - The Anthropic model to use (e.g., `claude-3-5-sonnet-20241022`). - **max_tokens** (integer) - Optional - The maximum number of tokens to generate. ### Request Example ```json { "stream": true, "messages": [ {"role": "user", "content": "Write a Python quicksort implementation."} ], "deepseek_config": { "headers": { "X-DeepSeek-API-Token": "YOUR_DEEPSEEK_KEY" } }, "anthropic_config": { "headers": { "X-Anthropic-API-Token": "YOUR_ANTHROPIC_KEY" } } } ``` ### Response #### Success Response (SSE Stream) Events are streamed as Server-Sent Events. Each event is prefixed with `event: ` and `data: `. - **start**: Indicates the stream has started. Contains a `created` timestamp. - **content**: Contains streaming deltas. `content` is an array of blocks, each with `text` (full block) and `text_delta` (incremental chunk). - **usage**: Contains final token counts and costs for each provider. - **done**: Indicates the stream has completed. - **error**: If an error occurs during streaming, this event provides error details. #### Example SSE Event (`content`) ``` event: content data: {"type": "content", "content": [{"type": "text", "text": "def quicksort(arr):\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n left = [x for x in arr if x < pivot]\n middle = [x for x in arr if x == pivot]\n right = [x for x in arr if x > pivot]\n return quicksort(left) + middle + quicksort(right)\n"}]} ``` ### Error Responses All errors return a JSON body with an `error` object containing `message`, `type`, and optional `param` and `code` fields. - **HTTP 400**: `missing_header` (e.g., missing API key), `invalid_system_prompt` (e.g., duplicate system prompts). - **Upstream API Failures**: `deepseek_*` or `anthropic_*` types. - **HTTP 500**: `internal_error` for internal server issues. ``` -------------------------------- ### Configure DeepReasoning Server Source: https://github.com/winfunc/deepreasoning/blob/main/README.md Create a TOML configuration file for server settings and pricing. ```toml [ server] host = "127.0.0.1" port = 3000 [pricing] # Configure pricing settings for usage tracking ``` -------------------------------- ### Server Configuration (`config.toml`) Source: https://context7.com/winfunc/deepreasoning/llms.txt Defines server host, port, and pricing for various AI models. Pricing is per million tokens. Defaults are used if the file is absent. ```toml [server] host = "127.0.0.1" port = 1337 [pricing.deepseek] input_cache_hit_price = 0.14 # $/M tokens (cached) input_cache_miss_price = 0.55 # $/M tokens (uncached) output_price = 2.19 # $/M tokens [pricing.anthropic.claude_3_sonnet] input_price = 3.0 output_price = 15.0 cache_write_price = 3.75 cache_read_price = 0.30 [pricing.anthropic.claude_3_haiku] input_price = 0.80 output_price = 4.0 cache_write_price = 1.0 cache_read_price = 0.08 [pricing.anthropic.claude_3_opus] input_price = 15.0 output_price = 75.0 cache_write_price = 18.75 cache_read_price = 1.50 ``` -------------------------------- ### Build DeepReasoning Project Source: https://github.com/winfunc/deepreasoning/blob/main/README.md Build the project using Cargo. Requires Rust 1.75+. ```bash cargo build --release ``` -------------------------------- ### Docker Deployment Commands Source: https://context7.com/winfunc/deepreasoning/llms.txt Commands to build and run the DeepReasoning application using Docker. Supports passing API keys and overriding host/port via environment variables. ```bash # Build and run with Docker docker build -t deepreasoning . docker run -p 1337:1337 deepreasoning # Or use Docker Compose docker-compose up # Pass API keys at runtime (override config host to bind publicly) docker run -p 1337:1337 \ -e DEEPREASONING_HOST=0.0.0.0 \ -e DEEPREASONING_PORT=1337 \ deepreasoning ``` -------------------------------- ### POST / — Chat Completion (Non-Streaming) Source: https://context7.com/winfunc/deepreasoning/llms.txt This endpoint provides chat completions using a non-streaming approach. It requires API tokens for both DeepSeek and Anthropic, and accepts a JSON body containing messages and optional configurations. The response includes the reasoning trace, the synthesized answer, and combined token usage and cost. ```APIDOC ## POST / ### Description This endpoint provides chat completions using a non-streaming approach. It requires API tokens for both DeepSeek and Anthropic, and accepts a JSON body containing messages and optional configurations. The response includes the reasoning trace, the synthesized answer, and combined token usage and cost. ### Method POST ### Endpoint / ### Parameters #### Headers - **X-DeepSeek-API-Token** (string) - Required - API token for DeepSeek. - **X-Anthropic-API-Token** (string) - Required - API token for Anthropic. #### Request Body - **stream** (boolean) - Optional - If false, returns a complete JSON response. - **verbose** (boolean) - Optional - If false, suppresses verbose output. - **system** (string) - Optional - A system prompt to guide the AI's behavior. - **messages** (array) - Required - An array of message objects, each with 'role' and 'content'. - **role** (string) - User or Assistant. - **content** (string) - The message content. ### Request Example ```json { "stream": false, "verbose": false, "system": "You are a concise assistant.", "messages": [ {"role": "user", "content": "How many rs are in the word strawberry?"} ] } ``` ### Response #### Success Response (200) - **created** (string) - Timestamp of creation. - **content** (array) - An array of content blocks. - **type** (string) - Type of content (e.g., 'text'). - **text** (string) - The content text, potentially including a reasoning trace. - **combined_usage** (object) - Combined token usage and cost information. - **total_cost** (string) - Total cost for the request. - **deepseek_usage** (object) - Usage details for DeepSeek. - **input_tokens** (integer) - **output_tokens** (integer) - **reasoning_tokens** (integer) - **cached_input_tokens** (integer) - **total_tokens** (integer) - **total_cost** (string) - **anthropic_usage** (object) - Usage details for Anthropic. - **input_tokens** (integer) - **output_tokens** (integer) - **cached_write_tokens** (integer) - **cached_read_tokens** (integer) - **total_tokens** (integer) - **total_cost** (string) #### Response Example ```json { "created": "2025-01-15T12:00:00Z", "content": [ { "type": "text", "text": "\nLet me count carefully: s-t-r-a-w-b-e-r-r-y. I see r at position 3, 8, 9. That's 3 rs.\n" }, { "type": "text", "text": "There are **3** letter \"r\"s in the word \"strawberry\"." } ], "combined_usage": { "total_cost": "$0.004", "deepseek_usage": { "input_tokens": 42, "output_tokens": 150, "reasoning_tokens": 120, "cached_input_tokens": 0, "total_tokens": 192, "total_cost": "$0.001" }, "anthropic_usage": { "input_tokens": 300, "output_tokens": 30, "cached_write_tokens": 0, "cached_read_tokens": 0, "total_tokens": 330, "total_cost": "$0.003" } } } ``` ``` -------------------------------- ### Non-Streaming Chat Completion API Request Source: https://context7.com/winfunc/deepreasoning/llms.txt Use this endpoint for chat completions when a complete JSON response is desired. Ensure both X-DeepSeek-API-Token and X-Anthropic-API-Token headers are provided. The response includes the reasoning trace and the final answer, along with combined token usage and cost. ```bash curl -X POST http://127.0.0.1:1337/ \ -H "Content-Type: application/json" \ -H "X-DeepSeek-API-Token: YOUR_DEEPSEEK_KEY" \ -H "X-Anthropic-API-Token: YOUR_ANTHROPIC_KEY" \ -d '{ "stream": false, "verbose": false, "system": "You are a concise assistant.", "messages": [ {"role": "user", "content": "How many rs are in the word strawberry?"} ] }' ``` ```json { "created": "2025-01-15T12:00:00Z", "content": [ { "type": "text", "text": "\nLet me count carefully: s-t-r-a-w-b-e-r-r-y. I see r at position 3, 8, 9. That's 3 rs.\n" }, { "type": "text", "text": "There are **3** letter \"r\"s in the word \"strawberry\"." } ], "combined_usage": { "total_cost": "$0.004", "deepseek_usage": { "input_tokens": 42, "output_tokens": 150, "reasoning_tokens": 120, "cached_input_tokens": 0, "total_tokens": 192, "total_cost": "$0.001" }, "anthropic_usage": { "input_tokens": 300, "output_tokens": 30, "cached_write_tokens": 0, "cached_read_tokens": 0, "total_tokens": 330, "total_cost": "$0.003" } } } ``` -------------------------------- ### API Request Body Schema Source: https://context7.com/winfunc/deepreasoning/llms.txt Defines the structure for API requests, including streaming options, verbose output, system prompts, messages, and provider-specific configurations. ```json { "stream": false, "verbose": false, "system": "You are an expert software engineer.", "messages": [ {"role": "user", "content": "Explain monads in Haskell."}, {"role": "assistant", "content": "A monad is a design pattern..."}, {"role": "user", "content": "Give me a concrete IO monad example."} ], "deepseek_config": { "headers": {}, "body": { "model": "deepseek-reasoner", "max_tokens": 4096, "temperature": 1.0 } }, "anthropic_config": { "headers": {}, "body": { "model": "claude-3-5-sonnet-20241022", "max_tokens": 8192 } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.