News for hackers. Stuff that matters.

zachkirsch

Show HN: An auto-generated OpenAI Node SDK that's better than the official one

https://github.com/fern-openai/openai-node

Some part of the OpenAI API can stream events, like the “chat completion” endpoint that’s used by ChatGPT to type out its response. However, the official OpenAI Node SDK doesn’t natively support streaming [1] (though it’s the most requested feature [2]). The recommended approach [3] is kind of a nightmare.I used Fern [4] to generate an SDK for the OpenAI API. It makes it a lot easier to stream...

( Read More... | no comments | 4 points | on HN )
Re:Fern: A cross-language alternative to tRPC on Tuesday March 07, 2023 @05:55PM (#35062497)
_Showing is better than telling:_ Here's a Loom if you want to see a demo of using Fern + Express: https://www.loom.com/share/31f4243c4d824c54938bdc4840fbb8ba

Hi HN,

I'm a huge tRPC fan because it subtly forces you to practice schema driven API development. You start by defining your API (using zod), and as a result, you get awesome autocomplete in your IDE.

However, there are a few things about tRPC I don't particularly like:

1. It's for TypeScript backends only! Sometimes I want the same value prop as tRPC but I need to write the backend in python (e.g. for ML applications).

2. It's for TypeScript frontends only! tRPC gives you a TypeScript client out of the box, but no other languages. You can go tRPC -> OpenAPI, but the OpenAPI-generated clients are pretty bad - definitely not up to the bar of what I'd show to a customer.

3. The wire format of tRPC's requests are pretty bonkers. They eschew normal REST conventions, so it's pretty painful to interact with tRPC from curl, Postman, and other languages besides TypeScript.

Fern is similar to tRPC but for cross-language development:

1. Define your API in a simple format - similar to OpenAPI but much easier to read and write.

2. Generate server boilerplate - very similar to the tRPC experience, but we support Express, FastAPI, and Java Spring. Here's a Loom if you want to see a demo of using Fern + Express: https://www.loom.com/share/31f4243c4d824c54938bdc4840fbb8ba

3. Generate client SDKs that are actually good. The initial spec is purpose-built for code generation, so the resulting SDKs are actually production quality - e.g. FlatFile uses Fern for their Node SDK! https://github.com/FlatFilers/flatfile-node.

4. Work with your favorite tools! You can easily generate an OpenAPI spec and Postman collection as well.

Show HN: Fern, a cross-language alternative to tRPC

https://github.com/fern-api/fern

_Showing is better than telling:_ Here's a [Loom](https://www.loom.com/share/31f4243c4d824c54938bdc4840fbb8ba) if you want to see a demo of using Fern + ExpressHi HN,I'm a huge tRPC fan because it subtly forces you to practice schema driven API development. You start by defining your API (using zod), and as a result, you get awesome autocomplete in your IDE.However, there are a few...

( Read More... | no comments | on HN )
> Smithy trait seem to be an escape hatch for everything, I believe it could be used to achieve the same but maybe not easier.

No doubt! This is definitely part of our thinking - there's a lot of things that are _possible_ in Smithy (and OpenAPI), but it requires you to be an expert and really understand how things work. For 90% of the use cases, it should be dead simple. For the remaining 10%, it's okay to rely on more complex features like plugins and traits.

Yes, we are! We're planning on offering a paid site where all the generation and publishing happens in the cloud.
Thanks for checking out Fern!

Smithy is an awesome library, and we love the VSCode extension that makes it easy to click around in the Smithy files.

We built our own spec because there's a lot of cool SDK features that aren't supported in Smithy. For example:

- Audiences. It should be easy in the spec to specify some endpoints as "internal only" to include them in the internal SDKs, but exclude them from the external SDKs.

- Per-endpoint errors. Smithy doesn't have a concept of specifying which non-200 responses a particular endpoint might return. It's super helpful in the SDKs to know which errors might be thrown from a particular endpoint.

- Pagination. It should be easy in the spec to specify that an endpoint is paginated, so the SDK is able to page through results easily (e.g. for-await in TypeScript). Note: this is a WIP and not yet released in Fern.

Having our own spec also lets us be more creative with the feature set we provide. For example, we want to add support for websockets and webhooks.

All that said, we're not aiming to be a competing standard. There's so much tooling already for these different specs, and it should be easy to convert between them. Our Smithy->Fern converter is in development so that Smithy users can take advantage of our SDK generators.

Show HN: Fern, a language for defining REST APIs that compiles into OpenAPI

https://github.com/fern-api/fern

Hi HN, this is Danny, Deep, and Zach.We built Fern after our previous ed tech startup failed. We were frustrated with how much time we spent writing “API code” instead of working on the actual product. We tried to use OpenAPI but we were underwhelmed - the generated code wasn’t idiomatic and it still required manual work (custom templates, scripts, manually publishing SDKs to registries).The...

( Read More... | 7 comments | 2 points | on HN )