Overview
The Computer Science Laboratory (CSLab) provides free access to Large Language Model (LLM) APIs for all undergraduate students whose home department is the Department of Computer Science at City University of Hong Kong.
This service enables students to integrate LLM capabilities into their programming projects, coursework, and personal learning activities without subscribing to commercial LLM API services.
With your personal CSLab API key, you can:
- Develop AI-powered applications: Integrate LLM capabilities into Python programs and other applications.
- Use AI coding assistants: Connect compatible AI-powered coding tools and agents to the CSLab LLM service.
- Access web search: Perform web searches through the CSLab Search MCP service using compatible MCP clients.
- Experiment with generative AI: Explore LLM capabilities for learning, software development, and experimentation.
- Eligibility
- All undergraduate students whose home department is Computer Science.
- Service charge
- Free of charge for eligible students.
- Authentication
- A personal CSLab API key is required.
1. Getting Started
Eligible students will receive a welcome email from CSLab containing:
- Your personal CSLab API key
- The designated LLM model name
- Instructions for accessing the service
Your API key is assigned exclusively to you and must not be shared with others.
Connection Settings
| Setting | Value |
|---|---|
| API Base URL | https://ai.cs.cityu.edu.hk/v1 |
| Search MCP Endpoint | https://ai.cs.cityu.edu.hk/web_tools/mcp |
| API Compatibility | OpenAI-compatible Chat Completions API |
| Authentication | Personal CSLab API key |
| Model Name | As specified in your welcome email |
Important: The API Base URL is used for LLM requests, while the Search MCP Endpoint is used for web searches. These endpoints serve different purposes and are not interchangeable.
2. Using the LLM API with Python
You can access the CSLab LLM service using the official OpenAI Python SDK.
Step 1: Install the OpenAI SDK
Open a terminal and run:
python -m pip install openai
Step 2: Create a Python Program
Create a Python file, such as test_llm.py, and enter the following code:
from openai import OpenAI
# Connect to the CSLab LLM API
client = OpenAI(
api_key="YOUR_CSLAB_API_KEY",
base_url="https://ai.cs.cityu.edu.hk/v1"
)
# Send a request to the LLM
response = client.chat.completions.create(
model="MODEL_NAME",
messages=[
{
"role": "user",
"content": "Write a short poem about artificial intelligence."
}
]
)
# Display the model's response
print(response.choices[0].message.content)
Step 3: Configure Your API Key and Model
Before running the program:
- Replace
YOUR_CSLAB_API_KEYwith your personal API key. - Replace
MODEL_NAMEwith the model name specified in your CSLab welcome email. - Keep the quotation marks around both values.
Security reminder: This example is intended for initial testing only. For regular development, store your API key in an environment variable rather than directly in your source code.
Step 4: Run the Program
Execute the Python file:
python test_llm.py
If the request is successful, the program will display the LLM's response.
You can modify the prompt to experiment with different tasks, such as text summarization, code generation, translation, and question answering.
3. Using the API with AI Assistants and Coding Agents
Your CSLab API key is not limited to Python applications.
You can also connect compatible AI assistants, coding agents, and development tools that support custom OpenAI-compatible Chat Completions endpoints.
Configuration
In your AI assistant or coding agent:
- Open the model or API provider settings.
- Select OpenAI Compatible, Custom OpenAI Provider, or an equivalent option.
- Configure the following settings:
| Setting | Value |
|---|---|
| Provider | OpenAI Compatible / Custom OpenAI |
| Base URL | https://ai.cs.cityu.edu.hk/v1 |
| API Key | Your personal CSLab API key |
| Model | Model name specified in your welcome email |
- Save the configuration and test the connection.
Important notes:
- Use the CSLab API Base URL, not the default OpenAI API endpoint.
- Do not use the Search MCP Endpoint for LLM requests.
- Compatibility depends on whether the application supports custom OpenAI-compatible endpoints and the required API features.
- Some advanced features offered by third-party tools may not be supported by the CSLab service.
4. Using Web Search through MCP
In addition to LLM access, CSLab provides a web search service through the Model Context Protocol (MCP).
MCP allows compatible AI applications to connect to external tools and services. Through the CSLab Search MCP service, supported clients can perform web searches to retrieve information from the internet.
Search MCP Connection Settings
| Setting | Value |
|---|---|
| MCP Endpoint | https://ai.cs.cityu.edu.hk/web_tools/mcp |
| Transport Protocol | Streamable HTTP |
| Authentication | Bearer Token |
| Bearer Token | Your personal CSLab API key |
| Search Tool | web_tools-search |
Configuration Steps
- Open an AI application that supports MCP.
- Add a new MCP server connection.
- Select Streamable HTTP as the transport protocol.
- Enter the CSLab Search MCP Endpoint.
- Configure authentication using your personal CSLab API key as a bearer token.
- Save the configuration and establish the connection.
- Select the
web_tools-searchtool to perform a web search.
Note: The Python example in Section 2 uses the LLM Chat Completions API only. It does not automatically perform web searches.
To enable web search, you must separately configure the Search MCP service in a compatible MCP client.
5. API Key Security and Acceptable Use
Your CSLab API key is a personal credential that grants access to departmental computing resources.
You are responsible for keeping your API key secure and preventing unauthorized use.
API Key Security
You must:
- Keep your API key confidential. Never share it with classmates or other individuals.
- Never publish your API key. Do not include it in GitHub repositories, public code-sharing platforms, websites, or online forums.
- Avoid hardcoding API keys. Use environment variables or secure credential storage whenever possible.
- Protect your submissions. Remove API keys from source code, notebooks, and configuration files before submitting coursework or sharing projects.
- Never disclose your key in AI conversations. Do not paste your API key into chat messages, prompts, or screenshots.
Prohibited Activities
The following activities are not permitted:
- Sharing or transferring API keys to other users.
- Allowing unauthorized individuals to access the service through your API key.
- Publishing API keys in publicly accessible locations.
- Using the service in ways that disrupt its availability or adversely affect other users.
Enforcement
CSLab reserves the right to deactivate any API key found to have been shared, exposed, or misused, immediately and without prior notice.
This measure is necessary to protect the security, reliability, and fair availability of the service for all eligible students.
What If Your API Key Is Exposed?
If you accidentally disclose your API key:
- Stop using the exposed key.
- Remove it from the affected files or platforms.
- Contact CSLab immediately to request a replacement key.
- Do not include the exposed API key in your message to CSLab.
Important: Removing an API key from a Git repository does not necessarily remove it from the repository's history. Always treat a publicly exposed API key as compromised.
6. Service Availability and Limitations
The CSLab LLM API is a shared departmental service intended to support undergraduate learning and experimentation.
To maintain service quality and fair access:
- The service may be subject to request limits or usage quotas.
- Response times may vary depending on system workload and available computing resources.
- Available models and supported features may change as the service evolves.
- CSLab may temporarily suspend access for system maintenance, security updates, or operational requirements.
Students should not rely on uninterrupted service availability for time-critical applications.
7. Support
If you encounter problems accessing the CSLab LLM API, please contact CSLab.
When reporting an issue, provide:
- Your CityU student ID
- The application or programming environment you are using
- The model name
- A description of the problem
- Any relevant error messages
Never include your API key in support requests, screenshots, or diagnostic logs.