https://github.com/nakasyou/ai-to-openai-hono
An adapter to add OpenAI compatibility to your Hono app using the Vercel AI SDK
https://github.com/nakasyou/ai-to-openai-hono
ai-sdk hono llm openai openai-compatible openai-compatible-api typescript vercel-ai-sdk
Last synced: 27 days ago
JSON representation
An adapter to add OpenAI compatibility to your Hono app using the Vercel AI SDK
- Host: GitHub
- URL: https://github.com/nakasyou/ai-to-openai-hono
- Owner: nakasyou
- License: mit
- Created: 2025-04-02T07:30:49.000Z (27 days ago)
- Default Branch: main
- Last Pushed: 2025-04-02T08:28:34.000Z (27 days ago)
- Last Synced: 2025-04-02T08:29:40.258Z (27 days ago)
- Topics: ai-sdk, hono, llm, openai, openai-compatible, openai-compatible-api, typescript, vercel-ai-sdk
- Language: TypeScript
- Homepage: https://jsr.io/@ns/hono-to-openai-hono
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ai-to-openai-hono
An adapter to add OpenAI compatibility to your Hono app using the Vercel AI SDK.
## Install
https://jsr.io/@ns/ai-to-openai-hono
## Usage
```ts
import { Hono } from 'hono'
import { createOpenAIHono } from '@ns/ai-to-openai-hono'import { anthropic } from 'npm:@ai-sdk/anthropic' // or your favorite provider
const app = new Hono() // Your existing or new Hono app
// Mount the OpenAI-compatible endpoint
app.route(
'/my-ai-endpoint',
createOpenAIHono({
languageModels: {
'claude-3.7-sonnet': anthropic('claude-3-7-sonnet-20250219'), // Map model names to Vercel AI SDK instances
// ... add more models here
},
// Optional: Add API key verification
verifyAPIKey(key) {
// In production, compare against securely stored keys (e.g., environment variables)
return key === 'this-is-super-secret-key'
},
}),
)export default app
```Next, run your Hono server. The OpenAI-compatible endpoint will then be
available.```ts
import { OpenAI } from 'openai'const openai = new OpenAI({
baseURL: 'http://localhost:8080/my-ai-endpoint',
apiKey: 'this-is-super-secret-key',
})const completion = await openai.chat.completions.create({
model: 'claude-3.7-sonnet',
// ...
})
console.log(completion.choices[0].message.content)
```