### Install Dependencies using Pip Source: https://github.com/e2b-dev/claude-code-fastapi/blob/main/README.md Installs project dependencies using 'pip'. This command installs the project in editable mode. ```bash pip install -e . ``` -------------------------------- ### Install Dependencies using UV Source: https://github.com/e2b-dev/claude-code-fastapi/blob/main/README.md Installs project dependencies using the 'uv' package manager. 'uv sync' is recommended for efficient dependency management. ```bash uv sync ``` -------------------------------- ### Run FastAPI Application Source: https://github.com/e2b-dev/claude-code-fastapi/blob/main/README.md Starts the FastAPI development server using 'uvicorn'. The '--reload' flag enables automatic server restarts on code changes. The API will be accessible at http://localhost:8000. ```bash uvicorn app.main:app --reload ``` -------------------------------- ### Clone Repository using Git Source: https://github.com/e2b-dev/claude-code-fastapi/blob/main/README.md Clones the project repository from GitHub. This is a prerequisite step before installing dependencies and running the application. ```bash git clone https://github.com/e2b-dev/claude-code-fastapi cd claude-code-fastapi ``` -------------------------------- ### Access API Documentation Source: https://github.com/e2b-dev/claude-code-fastapi/blob/main/README.md Navigates to the interactive API documentation for the running FastAPI application. This typically uses Swagger UI and is available at the '/docs' endpoint. ```bash http://localhost:8000/docs ``` -------------------------------- ### Start New Chat Session with GitHub Repo Source: https://github.com/e2b-dev/claude-code-fastapi/blob/main/README.md Initiates a new chat session with Claude Code via a POST request to the '/chat' endpoint. It includes a prompt and an optional GitHub repository URL to clone into the sandbox. ```bash curl -X POST "http://localhost:8000/chat" \ -H "Content-Type: application/json" \ -d '{ "prompt": "Can you add GPT 3.5-Turbo to the list of models and open a pull request on GitHub", "repo": "https://github.com/e2b-dev/fragments" }' ``` -------------------------------- ### Start or Resume Chat Session Source: https://github.com/e2b-dev/claude-code-fastapi/blob/main/README.md Initiates a new chat session with Claude Code or continues an existing one using a session ID. For new sessions, a GitHub repository can be provided to clone. ```APIDOC ## POST /chat Start a new conversation with Claude Code or resume an existing one. ### Method POST ### Endpoint `/chat` or `/chat/{session}` ### Parameters #### Path Parameters - **session** (string) - Optional - The ID of an existing session to resume. #### Query Parameters None #### Request Body - **prompt** (string) - Required - The prompt or command to send to Claude Code. - **repo** (string) - Optional - The URL of a GitHub repository to clone. This is only used when starting a new session (i.e., not providing a `session` path parameter). ### Request Example ```json { "prompt": "Can you add GPT 3.5-Turbo to the list of models and open a pull request on GitHub", "repo": "https://github.com/e2b-dev/fragments" } ``` ### Response #### Success Response (200) - **type** (string) - Type of the response, typically 'result'. - **subtype** (string) - Subtype of the result, typically 'success'. - **is_error** (boolean) - Indicates if an error occurred, false for success. - **duration_ms** (integer) - Total duration of the operation in milliseconds. - **duration_api_ms** (integer) - Duration of the API call processing in milliseconds. - **num_turns** (integer) - Number of conversational turns. - **result** (string) - The output or result from Claude Code. - **session_id** (string) - The ID of the current session. This is returned for both new and resumed sessions. - **total_cost_usd** (number) - The total cost of the operation in USD. - **usage** (object) - Token usage details. - **input_tokens** (integer) - Number of input tokens. - **cache_creation_input_tokens** (integer) - Input tokens used for cache creation. - **cache_read_input_tokens** (integer) - Input tokens read from cache. - **output_tokens** (integer) - Number of output tokens. - **server_tool_use** (object) - Tool usage details. - **web_search_requests** (integer) - Number of web search requests made. - **service_tier** (string) - The service tier used. - **permission_denials** (array) - List of permission denials, if any. #### Response Example ```json { "type": "result", "subtype": "success", "is_error": false, "duration_ms": 216401, "duration_api_ms": 216234, "num_turns": 81, "result": "Perfect! I have successfully completed all the tasks:\n\n✅ **All tasks completed!** The pull request has been created at: https://github.com/e2b-dev/fragments/pull/170\n\n## Summary\n\nI've successfully added GPT-3.5 Turbo to the model list and opened a pull request with the following changes:\n\n- **Added GPT-3.5 Turbo** to `/home/user/fragments/lib/models.json:108-114`\n- **Model configuration**:\n - ID: `gpt-3.5-turbo`\n - Provider: OpenAI\n - Name: GPT-3.5 Turbo \n - Multimodal: false\n- **Validated** JSON syntax is correct\n- **Created branch** `add-gpt-3.5-turbo` \n- **Opened PR #170** with comprehensive description\n\nThe pull request is ready for review and includes all the necessary changes to integrate GPT-3.5 Turbo into the fragments application.", "session_id": "038b769b-4717-47ca-be02-2a49bd7da978", "total_cost_usd": 1.1459241, "usage": { "input_tokens": 300, "cache_creation_input_tokens": 77458, "cache_read_input_tokens": 2087724, "output_tokens": 13935, "server_tool_use": { "web_search_requests": 0 }, "service_tier": "standard" }, "permission_denials": [] } ``` ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/e2b-dev/claude-code-fastapi/blob/main/README.md Sets up required and optional environment variables in a `.env` file for application configuration, including API keys for Anthropic, E2B, and optionally GitHub and Context7. ```env # Required ANTHROPIC_API_KEY=your_anthropic_api_key_here E2B_API_KEY=your_e2b_api_key_here # Optional E2B_SANDBOX_TEMPLATE=claude-code-dev # or claude-code for production GITHUB_PAT=your_github_personal_access_token_here CONTEXT7_API_KEY=your_context7_api_key_here # for MCP Context7 server ``` -------------------------------- ### Build Development Sandbox Template Source: https://github.com/e2b-dev/claude-code-fastapi/blob/main/README.md Builds the development E2B sandbox template using a Python script. This template is configured with specific CPU and memory resources and assigned an alias. ```bash cd template python build_dev.py ``` -------------------------------- ### API Response Example Source: https://github.com/e2b-dev/claude-code-fastapi/blob/main/README.md An example of a successful response from the chat API endpoint, detailing task completion, cost, usage statistics, and potential permission denials. ```json { "type": "result", "subtype": "success", "is_error": false, "duration_ms": 216401, "duration_api_ms": 216234, "num_turns": 81, "result": "Perfect! I have successfully completed all the tasks:\n\n✅ **All tasks completed!** The pull request has been created at: https://github.com/e2b-dev/fragments/pull/170\n\n## Summary\n\nI've successfully added GPT-3.5 Turbo to the model list and opened a pull request with the following changes:\n\n- **Added GPT-3.5 Turbo** to `/home/user/fragments/lib/models.json:108-114`\n- **Model configuration**:\n - ID: `gpt-3.5-turbo`\n - Provider: OpenAI\n - Name: GPT-3.5 Turbo \n - Multimodal: false\n- **Validated** JSON syntax is correct\n- **Created branch** `add-gpt-3.5-turbo` \n- **Opened PR #170** with comprehensive description\n\nThe pull request is ready for review and includes all the necessary changes to integrate GPT-3.5 Turbo into the fragments application.", "session_id": "038b769b-4717-47ca-be02-2a49bd7da978", "total_cost_usd": 1.1459241, "usage": { "input_tokens": 300, "cache_creation_input_tokens": 77458, "cache_read_input_tokens": 2087724, "output_tokens": 13935, "server_tool_use": { "web_search_requests": 0 }, "service_tier": "standard" }, "permission_denials": [] } ``` -------------------------------- ### Build Production Sandbox Template Source: https://github.com/e2b-dev/claude-code-fastapi/blob/main/README.md Builds the production E2B sandbox template using a Python script. This template is configured with specific CPU and memory resources and assigned an alias. ```bash cd template python build.py ``` -------------------------------- ### Resume Existing Chat Session Source: https://github.com/e2b-dev/claude-code-fastapi/blob/main/README.md Resumes an existing conversation using a session ID by sending a POST request to the '/chat/{session}' endpoint. The prompt is provided in the request body. ```bash curl -X POST "http://localhost:8000/chat/038b769b-4717-47ca-be02-2a49bd7da978" \ -H "Content-Type: application/json" \ -d '{ "prompt": "Now modify the script to accept a name parameter" }' ``` -------------------------------- ### Configure MCP Servers with JSON Source: https://github.com/e2b-dev/claude-code-fastapi/blob/main/README.md This JSON configuration allows you to add custom MCP servers to Claude Code. It specifies the server type, URL, and necessary headers like authentication tokens. Ensure the CONTEXT7_API_KEY environment variable is set for authorization. ```json { "mcpServers": { "context7": { "type": "http", "url": "https://mcp.context7.com/mcp", "headers": { "Authorization": "Bearer ${CONTEXT7_API_KEY}" } } } } ``` -------------------------------- ### API Request Body Schema Source: https://github.com/e2b-dev/claude-code-fastapi/blob/main/README.md Defines the structure of the JSON request body for the /chat and /chat/{session} API endpoints. It includes the 'prompt' (required) and 'repo' (optional, only for new sessions). ```json { "prompt": "string", // Required: The prompt/command for Claude Code "repo": "string" // Optional: GitHub repository URL to clone (only for new sessions) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.