How to Integrate Xunfei Starfire Cognitive Model into PHP Projects – Step-by-Step Guide

This guide walks you through the background of Xunfei's Starfire large language model, its 2.0 features, account setup, obtaining API credentials, cloning the example repository, installing dependencies, configuring keys, and troubleshooting common errors for PHP integration.

Open Source Tech Hub
Open Source Tech Hub
Open Source Tech Hub
How to Integrate Xunfei Starfire Cognitive Model into PHP Projects – Step-by-Step Guide

Starfire Cognitive Model

Starfire Cognitive Model (Starfire Cognitive Mode1) is an AI‑driven cognitive model that simulates human thinking and reasoning by combining natural language processing, machine learning, and knowledge‑graph technologies.

The model is trained on massive corpora to understand and answer questions, and it can be applied to intelligent customer service, Q&A systems, virtual assistants, and other scenarios.

Version 2.0 Features

Stronger natural language processing powered by larger training data and deeper neural networks, yielding more accurate and fluent responses.

Richer knowledge base that can provide professional, in‑depth explanations and suggestions.

More personalized service by leveraging user profiles and interaction history.

Higher security and reliability with multiple safeguards to protect data privacy and ensure stable operation.

Preparation

Access the Starfire portal: https://xinghuo.xfyun.cn/

Starfire portal screenshot
Starfire portal screenshot
API free trial is available.
Free token screenshot
Free token screenshot
Note: you must register an account first; existing accounts can skip this step.

Steps to obtain credentials:

Create a new application in the console and claim free tokens.

Retrieve APPID, APISecret and APIKey from the Open Platform console: https://console.xfyun.cn/services/cbm

Reference the Web API documentation: https://www.xfyun.cn/doc/spark/Web.html

Test the service via the online demo: https://xinghuo.xfyun.cn/desk

Example Code

Repository: https://gitee.com/Tinywan_admin/spark.chatgpt.tinywan.com

Get the Code

git clone [email protected]:Tinywan_admin/spark.chatgpt.tinywan.com.git

Installation

Third‑party WebSocket library used: https://github.com/Textalk/websocket-php
cd spark.chatgpt.tinywan.com
composer require textalk/websocket

Configure Credentials

Copy the APPID , APIKey and APISecret obtained from the console into the corresponding fields of Spark.php .
$Appid = "007e50a0";
$Apikey = "UyZmNjNxxxxxxxxxxxxGY1Mzk3";
$ApiSecret = "5459f0f1xxxxxxxxxxxxxxxd9ef7af4e";
Configuration file screenshot
Configuration file screenshot

Run a Test

Example: implement a bubble‑sort algorithm in PHP to verify the model call.
Bubble sort test screenshot
Bubble sort test screenshot

Common Issues

401 Unauthorized

Sec-WebSocket-Accept not found. Header:
HTTP/1.1 401 Unauthorized
Date: Sun, 22 Oct 2023 00:04:37 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Content-Length: 76
Server: kong/1.3.0
Solution: verify that ApiKey and SecretKey are not swapped.

AppIdNoAuthError

{
  "header": {
    "code": 11200,
    "message": "AppIdNoAuthError:(07:59:51.663) domain.general",
    "sid": "cht000a4b97@dx18b54ae4f68b8f3540",
    "status": 2
  }
}
Solution: ensure your account has permission to use the 2.0 model.
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

IntegrationAILLMPHPAPITutorialStarfire
Open Source Tech Hub
Written by

Open Source Tech Hub

Sharing cutting-edge internet technologies and practical AI resources.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.