|
| 1 | +# Contributing to CaptchaAI Examples |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This repository holds full working code examples that accompany [CaptchaAI blog articles](https://blog.captchaai.com). Each example is a complete, runnable project — not a snippet. |
| 6 | + |
| 7 | +## When to add an example |
| 8 | + |
| 9 | +An example pack should be created when: |
| 10 | + |
| 11 | +- The blog article type is: API tutorial, Tutorial, Integration guide, Framework, DevOps tutorial, Project tutorial, or Use case guide |
| 12 | +- The example provides clear value beyond the in-article code snippets |
| 13 | +- The article has a complete draft (not a placeholder) |
| 14 | +- The article's `editorial_review` is not `manual-only` |
| 15 | + |
| 16 | +Do **not** create an example pack when: |
| 17 | + |
| 18 | +- The in-article snippet is sufficient on its own |
| 19 | +- The article is a comparison, explainer, or reference with no meaningful runnable code |
| 20 | +- The example would be shallow or trivial (single API call with no workflow) |
| 21 | + |
| 22 | +## Structure |
| 23 | + |
| 24 | +Every example pack lives under `articles/{slug}/` and must contain: |
| 25 | + |
| 26 | +``` |
| 27 | +articles/{slug}/ |
| 28 | + README.md # Setup, usage, expected output, troubleshooting |
| 29 | + .env.example # All required environment variables |
| 30 | + .gitignore # Excludes .env, node_modules, vendor, __pycache__ |
| 31 | + python/ # Python implementation (if applicable) |
| 32 | + solve.py |
| 33 | + requirements.txt |
| 34 | + node/ # Node.js implementation (if applicable) |
| 35 | + solve.js |
| 36 | + package.json |
| 37 | + php/ # PHP implementation (if applicable) |
| 38 | + solve.php |
| 39 | + composer.json |
| 40 | +``` |
| 41 | + |
| 42 | +## Code requirements |
| 43 | + |
| 44 | +### API endpoints |
| 45 | + |
| 46 | +- Submit: `https://ocr.captchaai.com/in.php` |
| 47 | +- Poll: `https://ocr.captchaai.com/res.php` |
| 48 | +- Always use `json=1` for structured responses |
| 49 | + |
| 50 | +### Credentials |
| 51 | + |
| 52 | +- Load from `.env` file using dotenv |
| 53 | +- Use `YOUR_API_KEY` as the placeholder in `.env.example` |
| 54 | +- Never commit real API keys |
| 55 | + |
| 56 | +### Polling |
| 57 | + |
| 58 | +- Wait 15-20 seconds before first poll |
| 59 | +- Poll every 5 seconds |
| 60 | +- Handle `CAPCHA_NOT_READY` as normal in-progress |
| 61 | +- Implement a maximum timeout (default: 120 seconds) |
| 62 | + |
| 63 | +### Error handling |
| 64 | + |
| 65 | +Handle all documented error categories: |
| 66 | +- Auth errors → clear message about API key |
| 67 | +- Balance errors → message to top up |
| 68 | +- Input errors → parameter validation message |
| 69 | +- Transient errors → retry with exponential backoff |
| 70 | +- Solve errors → log and suggest parameter check |
| 71 | + |
| 72 | +### Expected output |
| 73 | + |
| 74 | +Include a section in the README showing what a successful run looks like. |
| 75 | + |
| 76 | +## README template |
| 77 | + |
| 78 | +Every example README must include: |
| 79 | + |
| 80 | +1. Title (matches the article) |
| 81 | +2. Description |
| 82 | +3. Link to the blog article |
| 83 | +4. Prerequisites |
| 84 | +5. Setup instructions (clone → install → configure → run) |
| 85 | +6. Environment variables table |
| 86 | +7. How it works |
| 87 | +8. Expected output |
| 88 | +9. Common errors table |
| 89 | +10. Troubleshooting |
| 90 | +11. API docs link |
| 91 | +12. Related examples |
| 92 | + |
| 93 | +## Linking |
| 94 | + |
| 95 | +- Example README links to: blog article, API docs, related examples |
| 96 | +- Blog article links to: example repo path |
| 97 | + |
| 98 | +## Quality checklist |
| 99 | + |
| 100 | +Before submitting: |
| 101 | + |
| 102 | +- [ ] Code uses real CaptchaAI API endpoints |
| 103 | +- [ ] `.env.example` lists all required variables |
| 104 | +- [ ] Setup instructions work from clone to first run |
| 105 | +- [ ] Error handling covers all documented error categories |
| 106 | +- [ ] Expected output is accurate |
| 107 | +- [ ] README links back to the blog article |
| 108 | +- [ ] No real API keys or secrets in the code |
| 109 | +- [ ] Code follows the language's standard style guide |
| 110 | + |
| 111 | +## Scaffolding |
| 112 | + |
| 113 | +New example packs are scaffolded using the tool in the `cai_content` repository: |
| 114 | + |
| 115 | +```bash |
| 116 | +python scripts/scaffold_example_pack.py articles/{slug}.md --examples-repo ../CaptchaAI-Examples |
| 117 | +``` |
| 118 | + |
| 119 | +This generates the directory structure, README template, `.env.example`, and starter code files. |
| 120 | + |
| 121 | +## Languages |
| 122 | + |
| 123 | +- Primary language is selected based on the article's ICP (Ideal Customer Profile) |
| 124 | +- 1 canonical full implementation per example |
| 125 | +- Optionally 2 languages for high-value articles |
| 126 | +- Do not force all languages for every example |
0 commit comments