Implement Typing Effect Streaming Output in Scriptcase (AI API Connection Implementation)

We are developing a Scriptcase-based application that integrates AI APIs (e.g., DeepSeek/OpenAI) and requires a ChatGPT-like character-by-character streaming effect (text appears progressively instead of all at once). We face the following challenges and would appreciate insights from the community:

  1. Frontend Dynamic Rendering

How to implement character-by-character display in Scriptcase’s web interface? Is this achievable purely via JavaScript, or can Scriptcase’s native features be leveraged?
Are there recommended frontend libraries/code patterns (e.g., Typed.js for animation vs. SSE/WebSocket for real streaming)?

  1. Streaming API Integration

For AI APIs supporting streaming responses (e.g., stream: true), how to properly handle chunked data in the backend (PHP) and relay it to the frontend?
Are there successful cases using Scriptcase’s AJAX features or custom PHP scripts for streaming?

  1. Scriptcase Compatibility

Does Scriptcase natively support Server-Sent Events (SSE) or WebSocket? If not, what workarounds exist?

  1. Performance & Stability

How to ensure smooth rendering for long responses (>1000 characters)? Is a chunk buffering mechanism required?
Are there known limitations for streaming implementations in Scriptcase under high concurrency?

We have integrated the OpenAI API successfully. As you noted, rendering responses takes some time. Have you found a solution, perhaps using chunk buffering with stream: true?

AI API Connection Implementation

  1. Typing Effect Implementation

    • The typing effect should be implemented using JavaScript.
    • The front-end JavaScript code calls a PHP file on the server.
    • The PHP file on the server calls the AI API and sends the result back to the front end.
    • The front-end JavaScript then directly displays the result in the UI component with typing Effect.
  2. API Key Management

    • The API key is stored in the database and used by the PHP script on the server to make API requests. I hope this is a safe way, let me know if you have other idea. AI recommend to store in Env but I am not.
  3. Storing AI Responses

    • The AI-generated responses are stored in the database for future queries and further processing.
  4. AI-Generated Code

    • AI can generate the required code, so I won’t provide code snippets here.

I hope that Scriptcase official can soon release a version that integrates various AI models, enhancing its market competitiveness.
Feel free to ask questions — I will do my best to share my insights.

1 Like