Skip to content

Commit 3b18355

Browse files
committed
feat: initial release v1.0.0
- OpenAI-compatible API gateway for OpenCode CLI - Support for Chat Completions and Responses API - Streaming and reasoning control support - Docker deployment ready - Only Chinese documentation
0 parents  commit 3b18355

27 files changed

Lines changed: 9252 additions & 0 deletions

.dockerignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
node_modules
2+
npm-debug.log
3+
.git
4+
.gitignore
5+
*.md
6+
!README.md
7+
config.json
8+
config.json.example
9+
tests
10+
.DS_Store
11+
*.log
12+
.env
13+
.env.*

.editorconfig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# EditorConfig helps maintain consistent coding styles
2+
# https://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[*.{js,jsx,ts,tsx,json}]
13+
indent_style = space
14+
indent_size = 4
15+
16+
[*.md]
17+
trim_trailing_whitespace = false
18+
19+
[*.{yml,yaml}]
20+
indent_style = space
21+
indent_size = 2
22+
23+
[*.sh]
24+
indent_style = space
25+
indent_size = 4
26+
27+
[Makefile]
28+
indent_style = tab

.env.example

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copy this file to .env before running docker compose.
2+
3+
API_KEY=change-me
4+
OPENCODE_SERVER_PASSWORD=change-me-too
5+
6+
# Safer default. Keep true unless you really want model tool access.
7+
DISABLE_TOOLS=true
8+
9+
# Helpful when running behind OpenClaw or other clients that already manage prompts.
10+
OPENCODE_PROXY_PROMPT_MODE=plugin-inject
11+
OPENCODE_PROXY_OMIT_SYSTEM_PROMPT=true
12+
13+
# Periodically clean proxy-owned conversation/session storage.
14+
OPENCODE_PROXY_AUTO_CLEANUP_CONVERSATIONS=true
15+
OPENCODE_PROXY_CLEANUP_INTERVAL_MS=43200000
16+
OPENCODE_PROXY_CLEANUP_MAX_AGE_MS=86400000
17+
18+
# Optional overrides
19+
# OPENCODE_PROXY_PORT=10000
20+
# OPENCODE_SERVER_PORT=10001
21+
# OPENCODE_USE_ISOLATED_HOME=false
22+
# OPENCODE_PROXY_REQUEST_TIMEOUT_MS=180000
23+
# OPENCODE_PROXY_DEBUG=false
24+
# OPENCODE_ZEN_API_KEY=
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Publish Docker Image
2+
3+
on:
4+
push:
5+
branches: ['main']
6+
tags: ['v*.*.*']
7+
workflow_dispatch:
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: tiarabasori/opencode2api
12+
13+
jobs:
14+
build-and-push:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: Log in to the Container registry
28+
uses: docker/login-action@v3
29+
with:
30+
registry: ${{ env.REGISTRY }}
31+
username: ${{ github.actor }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Extract metadata (tags, labels) for Docker
35+
id: meta
36+
uses: docker/metadata-action@v5
37+
with:
38+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
39+
tags: |
40+
type=ref,event=branch
41+
type=semver,pattern={{version}}
42+
type=raw,value=${{ github.run_number }}
43+
type=raw,value=latest,enable={{is_default_branch}}
44+
45+
- name: Build and push Docker image
46+
uses: docker/build-push-action@v5
47+
with:
48+
context: .
49+
file: ./Dockerfile
50+
push: true
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}
53+
cache-from: type=gha
54+
cache-to: type=gha,mode=max

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
.DS_Store
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
.env
8+
config.json

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.0.0] - 2025-04-11
9+
10+
### Added
11+
12+
- **OpenAI-compatible API**: `/v1/models`, `/v1/chat/completions`, `/v1/responses` endpoints
13+
- **Streaming Support**: Full SSE streaming for Chat Completions and Responses API
14+
- **Model Aliases**: GPT-style model aliasing (e.g., `gpt5-nano``gpt-5-nano`)
15+
- **Docker Deployment**: Complete Docker setup with healthcheck and volume management
16+
- **Configuration**: Environment variables and config.json support
17+
- **Auto Cleanup**: Configurable automatic conversation/session storage cleanup
18+
19+
### Changed
20+
21+
- **Default Security**: `DISABLE_TOOLS` defaults to `true` for safer out-of-box behavior

CONTRIBUTING.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Contributing to opencode2api
2+
3+
Thank you for your interest in contributing to opencode2api!
4+
5+
## Code of Conduct
6+
7+
Please be respectful and professional. We follow the [Contributor Covenant](https://www.contributor-covenant.org/).
8+
9+
## How to Contribute
10+
11+
### Reporting Bugs
12+
13+
1. Check if the issue already exists
14+
2. Create a detailed issue with:
15+
- Clear title and description
16+
- Steps to reproduce
17+
- Environment details
18+
- Relevant logs
19+
20+
### Suggesting Features
21+
22+
1. Open an issue with `[Feature Request]` prefix
23+
2. Describe the use case
24+
3. Propose a solution or API design
25+
26+
### Pull Requests
27+
28+
1. Fork the repository
29+
2. Create a feature branch: `git checkout -b feature/your-feature`
30+
3. Make your changes
31+
4. Run tests: `npm test`
32+
5. Commit with clear messages (see Commit Style below)
33+
6. Push to your fork
34+
7. Submit a Pull Request
35+
36+
## Commit Style
37+
38+
We follow [Conventional Commits](https://www.conventionalcommits.org/):
39+
40+
```
41+
<type>(<scope>): <description>
42+
43+
[optional body]
44+
45+
[optional footer]
46+
```
47+
48+
Types:
49+
- `feat`: New feature
50+
- `fix`: Bug fix
51+
- `docs`: Documentation
52+
- `style`: Code style (formatting)
53+
- `refactor`: Code refactoring
54+
- `test`: Tests
55+
- `chore`: Build/ci updates
56+
57+
Examples:
58+
```
59+
feat(api): add streaming support for Responses API
60+
fix(proxy): resolve memory leak in long-running sessions
61+
docs: update configuration documentation
62+
```
63+
64+
## Development Setup
65+
66+
```bash
67+
# Clone and install
68+
git clone https://github.com/TiaraBasori/opencode2api.git
69+
cd opencode2api
70+
npm install
71+
72+
# Run tests
73+
npm test
74+
75+
# Start locally
76+
npm start
77+
```
78+
79+
## Testing
80+
81+
- Unit tests: `npm run test:unit`
82+
- Integration tests: `npm run test:integration`
83+
- All tests: `npm test -- --runInBand`
84+
85+
## Code Review Process
86+
87+
1. All submissions require review
88+
2. Address feedback promptly
89+
3. Squash commits before merge
90+
91+
## License
92+
93+
By contributing, you agree that your contributions will be licensed under the [MIT License](./LICENSE.md).

Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
FROM node:lts-slim
2+
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
4+
git \
5+
curl \
6+
ca-certificates \
7+
&& dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')" \
8+
&& curl -Lo /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/1.17/gosu-$dpkgArch" \
9+
&& chmod +x /usr/local/bin/gosu \
10+
&& gosu --version \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
RUN npm install -g opencode-ai
14+
15+
RUN mkdir -p /home/node/.local/share/opencode \
16+
&& mkdir -p /home/node/.config/opencode \
17+
&& mkdir -p /home/node/project \
18+
&& chown -R node:node /home/node
19+
20+
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
21+
RUN chmod +x /usr/local/bin/entrypoint.sh
22+
23+
WORKDIR /home/node/project
24+
25+
COPY package*.json ./
26+
RUN npm install --production
27+
28+
COPY . .
29+
30+
EXPOSE 10000 10001
31+
32+
ENV OPENCODE_SERVER_PASSWORD=
33+
ENV API_KEY=
34+
ENV BIND_HOST=0.0.0.0
35+
ENV DISABLE_TOOLS=true
36+
ENV OPENCODE_USE_ISOLATED_HOME=false
37+
ENV OPENCODE_PROXY_DEBUG=false
38+
ENV OPENCODE_PROXY_PROMPT_MODE=standard
39+
ENV OPENCODE_PROXY_OMIT_SYSTEM_PROMPT=false
40+
ENV OPENCODE_PROXY_AUTO_CLEANUP_CONVERSATIONS=false
41+
ENV OPENCODE_PROXY_CLEANUP_INTERVAL_MS=43200000
42+
ENV OPENCODE_PROXY_CLEANUP_MAX_AGE_MS=86400000
43+
ENV OPENCODE_PROXY_REQUEST_TIMEOUT_MS=180000
44+
45+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
46+
CMD ["opencode", "serve", "--hostname", "0.0.0.0", "--port", "10001"]

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024-2025 opencode2api Contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)