GitCode API Usage: Standardized Invocation of GitCode REST API via Agent Skill

Introduction

When building automation for repositories, Pull Requests, Issues, or search on GitCode, manually writing httpx requests and piecing together paths and parameters based on English documentation often leads to errors in authentication, resource paths, and pagination parameters within Agents or scripts. The community-maintained gitcode-api Python SDK has encapsulated synchronous/asynchronous clients, APIs grouped by resource, and a built-in CLI. Meanwhile, the GitCode API Usage Skill on SkillHub (Coordinate: @user_f6d71f82/gitcode-api) codifies these conventions into SKILL instructions readable by Agents, facilitating consistent usage when writing Python, explaining calls like client.repos.get() or client.pulls.list(), or running bundled scripts for environment validation.

Below is an introduction to this Skill’s positioning, capabilities, and how to enable it.

What is this?

GitCode API Usage is a dev-programming Skill sourced from the SkillHub community (community), currently at version 1.1.0, published by user_f6d71f82. The page is tagged with requires_api_key=true, meaning an access token is required for actual calls to GitCode.

The Skill itself does not replace the GitCode server side; it centers around the gitcode-api lightweight Python SDK and its accompanying CLI, explaining how to interact with the GitCode REST API. Extended reading from official resources includes:

  • Documentation: https://gitcode-api.readthedocs.io/
  • PyPI: https://pypi.org/project/gitcode-api
  • GitHub: https://github.com/Trenza1ore/GitCode-API
  • GitCode Mirror: https://gitcode.com/SushiNinja/GitCode-API

SkillHub Display Data (as of page capture): Rating 100000, Downloads 740, Installs 1.

Core Functions

Based on the Skill’s introduction and the official gitcode-api documentation, the capabilities covered by the Skill can be summarized as:

  1. Python SDK: Synchronous and asynchronous clients GitCode / AsyncGitCode, built on httpx with a consistent API surface.
  2. OpenAI-style Resource Structure: Access endpoints via resource groups like client.repos, client.pulls, client.issues, client.users, and client.search. Default owner / repo can be set on the client to reduce repetitive parameter passing.
  3. Types and Serialization: Responses are typed models. The as_dict utility at the package root can convert single objects or lists into dict / list[dict].
  4. Authentication: Supports passing api_key directly or via the environment variable GITCODE_ACCESS_TOKEN; encrypted tokens can be decrypted via a decrypt callback before use.
  5. CLI: After installing the package, subcommands gitcode-api or python -m gitcode_api are available, corresponding to synchronous resource methods. An optional [mcp] extra provides capabilities like gitcode-api serve (requires Python 3.10+ according to documentation).
  6. Agent-oriented Integration (gitcode_api.llm in SDK docs): OpenAI-style tools, FastMCP, openJiuwen, etc., consistent with the “OpenAI-style client structure” hint in the Skill. The Skill’s focus remains on REST automation and SDK/CLI usage instructions.

Installation and Activation

Installing the Skill on SkillHub

The installation prompt provided on the SkillHub page is: Ask the AI to install the coordinate @user_f6d71f82/gitcode-api based on https://skillhub.cn/install/skillhub.md.

Skill Metadata URL: https://api.skillhub.cn/user_f6d71f82/gitcode-api
Skill Display Page: https://www.skillhub.cn/skills/user_f6d71f82/gitcode-api

Specific menu steps for different IDEs or CLIs should follow the SkillHub installation documentation; differences not explicitly detailed on the official page are omitted here.

Installing the Python SDK (for running scripts or CLI)

In environments where you need to execute gitcode-api or from gitcode_api import GitCode locally, install from PyPI:

pip install -U gitcode-api

If only the MCP-related CLI (gitcode-api serve) is needed, documentation requires Python 3.10+ and installation of the optional dependencies:

pip install 'gitcode-api[mcp]'

Configuring Access Token

Write the token to an environment variable (consistent with SDK documentation):

export GITCODE_ACCESS_TOKEN="your-token"

Or pass api_key in the code; if the token is stored encrypted, pass the decrypt callback as per documentation.

Typical Usage

The following examples are from the official gitcode-api Quick Start and are consistent with the client.repos.get(), client.pulls.list() call styles described in the Skill. Please ensure a valid token is configured before running.

Synchronous Client: Reading Repository and Branches under Default Repo

After setting owner and repo on the client, resource methods can omit repository parameters:

from gitcode_api import GitCode

client = GitCode(
    owner="SushiNinja",
    repo="GitCode-API",
)

repo = client.repos.get()
branches = client.branches.list(per_page=5)

print(repo.full_name)
for branch in branches:
    print(branch.name)

Asynchronous Client: Listing Open Pull Requests

import asyncio
from gitcode_api import AsyncGitCode

async def main() -> None:
    client = AsyncGitCode(owner="SushiNinja", repo="GitCode-API")
    pulls = await client.pulls.list(state="open", per_page=20)
    print(len(pulls))

asyncio.run(main())

CLI: Command Line Corresponding to SDK Resource Methods

When writing a separate script isn’t necessary, you can directly call the CLI (documentation example):

gitcode-api repos get --api-key "$GITCODE_ACCESS_TOKEN" --owner SushiNinja --repo GitCode-API
python -m gitcode_api pulls list --api-key "$GITCODE_ACCESS_TOKEN" --owner SushiNinja --repo GitCode-API --state open

Common Workflow Snippets

Get the current authenticated user:

from gitcode_api import GitCode

client = GitCode()
user = client.users.me()
print(user.login)

Search repositories:

from gitcode_api import GitCode

client = GitCode()
repos = client.search.repositories(q="sdk language:python", per_page=10)
for repo in repos:
    print(repo.full_name)

When using context managers, GitCode / AsyncGitCode will close the underlying httpx client upon exiting the with / async with block, making it suitable for short-lived scripts.

Use Cases and Notes

Who it is for

  • Developers writing Agents or Python automation scripts that need to access GitCode and want to unify on a resource-style client rather than scattered native HTTP calls.
  • Users debugging or explaining SDK calls (e.g., repos.get, pulls.list) who need to cross-reference with the official CLI, type models, and documentation.
  • Users needing short examples for repos, PRs, users, search, or wanting to use bundled scripts within the Skill for environment validation and simple CLI calls.

Usage Notes

  • The Skill is marked as requiring an API Key; do not commit real tokens to repositories or conversation logs. Prioritize using environment variables.
  • The Skill version is 1.1.0, but the underlying PyPI package evolves independently. In case of behavioral differences, defer to readthedocs and PyPI.
  • The SDK is a community-maintained project with broad coverage but is still iterating; enterprise networks or self-signed certificate scenarios may require configuring TLS options like verify for the httpx client as per documentation.
  • MCP, the [mcp] extra, and openJiuwen have additional requirements for Python versions; please check the installation instructions before enabling them.

Conclusion

GitCode API Usage consolidates GitCode REST automation onto the conventions of the gitcode-api SDK, CLI, and authentication, suitable for reducing the repetitive work of “checking docs to piece together requests” within Agent workflows. To install or update the Skill, use the coordinate @user_f6d71f82/gitcode-api and refer to the SkillHub installation documentation and the official metadata URL: https://api.skillhub.cn/user_f6d71f82/gitcode-api .

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye